aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2012-04-20 11:01:54 -0700
committerJohn MacFarlane <fiddlosopher@gmail.com>2012-04-20 11:01:54 -0700
commit255897b66a0d6d3999ff1e923ebc925d46ff153c (patch)
tree1973e9d72adcdf90de303cfa09ea288a8fe7d12e /src/Text/Pandoc
parent5adda4762f56587504c151da20d47457d5234ee7 (diff)
downloadpandoc-255897b66a0d6d3999ff1e923ebc925d46ff153c.tar.gz
DocBook reader: Refactored with new function attrValue.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Readers/DocBook.hs25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/Text/Pandoc/Readers/DocBook.hs b/src/Text/Pandoc/Readers/DocBook.hs
index 30a1cd7ee..826fed8b8 100644
--- a/src/Text/Pandoc/Readers/DocBook.hs
+++ b/src/Text/Pandoc/Readers/DocBook.hs
@@ -3,7 +3,6 @@ import Text.Pandoc.Parsing (ParserState(..))
import Text.Pandoc.Definition
import Text.Pandoc.Builder
import Text.XML.Light
-import Data.Maybe (fromMaybe)
import Data.Monoid
import Data.Char (isSpace)
import Control.Monad.State
@@ -510,6 +509,13 @@ readDocBook st inp = setTitle (dbDocTitle st')
, dbDocDate = mempty
}
+-- convenience function to get an attribute value, defaulting to ""
+attrValue :: String -> Element -> String
+attrValue attr elt =
+ case lookupAttrBy (\x -> qName x == attr) (elAttribs elt) of
+ Just z -> z
+ Nothing -> ""
+
parseBlock :: Content -> DB Blocks
parseBlock (Text (CData CDataRaw _ _)) = return mempty -- DOCTYPE
parseBlock (Text (CData _ s _)) = if all isSpace s
@@ -595,19 +601,14 @@ parseInline (Elem e) =
"constant" -> return $ codeWith ("",["constant"],[]) $ strContent e
"userinput" -> return $ codeWith ("",["userinput"],[]) $ strContent e
"varargs" -> return $ str "(…)"
- "ulink" -> link
- (fromMaybe "" (lookupAttrBy (\attr -> qName attr == "url")
- (elAttribs e))) "" <$> innerInlines
+ "ulink" -> link (attrValue "url" e) "" <$> innerInlines
"link" -> case findAttr (QName "href" Nothing $ Just "xlink") e of
Just href -> link href "" <$> innerInlines
- _ -> link ('#':anchor) "" <$> innerInlines
- where anchor = fromMaybe "" $ lookupAttrBy
- (\attr -> qName attr == "linkend")
- (elAttribs e)
- "emphasis" -> case lookupAttrBy (\attr -> qName attr == "role")
- (elAttribs e) of
- Just "strong" -> strong <$> innerInlines
- _ -> emph <$> innerInlines
+ _ -> link ('#' : attrValue "linkend" e) ""
+ <$> innerInlines
+ "emphasis" -> case attrValue "role" e of
+ "strong" -> strong <$> innerInlines
+ _ -> emph <$> innerInlines
"footnote" -> (note . mconcat) <$> (mapM parseBlock $ elContent e)
_ -> innerInlines
where innerInlines = (trimInlines . mconcat) <$>