@@ -3,7 +3,6 @@ import Text.Pandoc.Parsing (ParserState(..))
33import Text.Pandoc.Definition
44import Text.Pandoc.Builder
55import Text.XML.Light
6−import Data.Maybe (fromMaybe)
76import Data.Monoid
87import Data.Char (isSpace)
98import Control.Monad.State
@@ -510,6 +509,13 @@ readDocBook st inp = setTitle (dbDocTitle st')
510509 , dbDocDate = mempty
511510 }
512511
512+-- convenience function to get an attribute value, defaulting to ""
513+attrValue :: String -> Element -> String
514+attrValue attr elt =
515+ case lookupAttrBy (\x -> qName x == attr) (elAttribs elt) of
516+ Just z -> z
517+ Nothing -> ""
518+
513519parseBlock :: Content -> DB Blocks
514520parseBlock (Text (CData CDataRaw _ _)) = return mempty -- DOCTYPE
515521parseBlock (Text (CData _ s _)) = if all isSpace s
@@ -595,19 +601,14 @@ parseInline (Elem e) =
595601 "constant" -> return $ codeWith ("",["constant"],[]) $ strContent e
596602 "userinput" -> return $ codeWith ("",["userinput"],[]) $ strContent e
597603 "varargs" -> return $ str "(…)"
598− "ulink" -> link
599− (fromMaybe "" (lookupAttrBy (\attr -> qName attr == "url")
600− (elAttribs e))) "" <$> innerInlines
604+ "ulink" -> link (attrValue "url" e) "" <$> innerInlines
601605 "link" -> case findAttr (QName "href" Nothing $ Just "xlink") e of
602606 Just href -> link href "" <$> innerInlines
603− _ -> link ('#':anchor) "" <$> innerInlines
604− where anchor = fromMaybe "" $ lookupAttrBy
605− (\attr -> qName attr == "linkend")
606− (elAttribs e)
607− "emphasis" -> case lookupAttrBy (\attr -> qName attr == "role")
608− (elAttribs e) of
609− Just "strong" -> strong <$> innerInlines
610− _ -> emph <$> innerInlines
607+ _ -> link ('#' : attrValue "linkend" e) ""
608+ <$> innerInlines
609+ "emphasis" -> case attrValue "role" e of
610+ "strong" -> strong <$> innerInlines
611+ _ -> emph <$> innerInlines
611612 "footnote" -> (note . mconcat) <$> (mapM parseBlock $ elContent e)
612613 _ -> innerInlines
613614 where innerInlines = (trimInlines . mconcat) <$>