@@ -12,7 +12,7 @@ Conversion of DocBook XML to 'Pandoc' document.
1212-}
1313module Text.Pandoc.Readers.DocBook ( readDocBook ) where
1414import Control.Monad.State.Strict
15−import Data.Char (isSpace, toUpper, isLetter)
15+import Data.Char (isSpace, isLetter)
1616import Data.Default
1717import Data.Either (rights)
1818import Data.Foldable (asum)
@@ -540,8 +540,9 @@ instance Default DBState where
540540
541541readDocBook :: PandocMonad m => ReaderOptions -> Text -> m Pandoc
542542readDocBook _ inp = do
543− tree <- either (throwError . PandocXMLError "") (return . normalizeTree) $
544− parseXMLContents (TL.fromStrict . handleInstructions $ crFilter inp)
543+ tree <- either (throwError . PandocXMLError "") return $
544+ parseXMLContents
545+ (TL.fromStrict . handleInstructions $ crFilter inp)
545546 (bs, st') <- flip runStateT (def{ dbContent = tree }) $ mapM parseBlock tree
546547 return $ Pandoc (dbMeta st') (toList . mconcat $ bs)
547548
@@ -571,25 +572,6 @@ getFigure e = do
571572 modify $ \st -> st{ dbFigureTitle = mempty, dbFigureId = mempty }
572573 return res
573574
574−-- normalize input, consolidating adjacent Text and CRef elements
575−normalizeTree :: [Content] -> [Content]
576−normalizeTree = everywhere (mkT go)
577− where go :: [Content] -> [Content]
578− go (Text (CData CDataRaw _ _):xs) = xs
579− go (Text (CData CDataText s1 z):Text (CData CDataText s2 _):xs) =
580− Text (CData CDataText (s1 <> s2) z):xs
581− go (Text (CData CDataText s1 z):CRef r:xs) =
582− Text (CData CDataText (s1 <> convertEntity r) z):xs
583− go (CRef r:Text (CData CDataText s1 z):xs) =
584− Text (CData CDataText (convertEntity r <> s1) z):xs
585− go (CRef r1:CRef r2:xs) =
586− Text (CData CDataText (convertEntity r1 <>
587− convertEntity r2) Nothing):xs
588− go xs = xs
589−
590−convertEntity :: Text -> Text
591−convertEntity e = maybe (T.map toUpper e) T.pack (lookupEntity $ T.unpack e)
592−
593575-- convenience function to get an attribute value, defaulting to ""
594576attrValue :: Text -> Element -> Text
595577attrValue attr elt =