git.iko.soy/typeable/pandoc
on master help sign in
DocBook reader: Implemented glossary, simplified sect.
023bb2bJohn MacFarlane
src/Text/Pandoc/Readers/DocBook.hs+34−31
@@ -150,15 +150,15 @@ List of all DocBook tags, with [x] indicating implemented,
150[ ] funcsynopsisinfo - Information supplementing the FuncDefs of a FuncSynopsis
150[ ] funcsynopsisinfo - Information supplementing the FuncDefs of a FuncSynopsis
151[x] function - The name of a function or subroutine, as in a
151[x] function - The name of a function or subroutine, as in a
152 programming language
152 programming language
153−[ ] glossary - A glossary
153+[x] glossary - A glossary
154−[ ] glossaryinfo - Meta-information for a Glossary
154+[x] glossaryinfo - Meta-information for a Glossary
155−[ ] glossdef - A definition in a GlossEntry
155+[x] glossdef - A definition in a GlossEntry
156−[ ] glossdiv - A division in a Glossary
156+[x] glossdiv - A division in a Glossary
157−[ ] glossentry - An entry in a Glossary or GlossList
157+[x] glossentry - An entry in a Glossary or GlossList
158−[ ] glosslist - A wrapper for a set of GlossEntrys
158+[x] glosslist - A wrapper for a set of GlossEntrys
159−[ ] glosssee - A cross-reference from one GlossEntry to another
159+[x] glosssee - A cross-reference from one GlossEntry to another
160−[ ] glossseealso - A cross-reference from one GlossEntry to another
160+[x] glossseealso - A cross-reference from one GlossEntry to another
161−[ ] glossterm - A glossary term
161+[x] glossterm - A glossary term
162[ ] graphic - A displayed graphical object (not an inline)
162[ ] graphic - A displayed graphical object (not an inline)
163[ ] graphicco - A graphic that contains callout areas
163[ ] graphicco - A graphic that contains callout areas
164[ ] group - A group of elements in a CmdSynopsis
164[ ] group - A group of elements in a CmdSynopsis
@@ -595,13 +595,18 @@ parseBlock (Elem e) =
595 "titleabbrev" -> return mempty
595 "titleabbrev" -> return mempty
596 "authorinitials" -> return mempty
596 "authorinitials" -> return mempty
597 "title" -> return mempty -- handled by getTitle or sect
597 "title" -> return mempty -- handled by getTitle or sect
598− "bibliography" -> do
598+ "bibliography" -> sect 0
599− book <- gets dbBook
600− if book then sect 0 else sect 1
601− "bibliodiv" -> do
599+ "bibliodiv" -> sect 1
602− book <- gets dbBook
603− if book then sect 1 else sect 2
604 "biblioentry" -> para <$> getInlines e
600 "biblioentry" -> para <$> getInlines e
601+ "glosssee" -> para . (\ils -> text "See " <> ils <> str ".")
602+ <$> getInlines e
603+ "glossseealso" -> para . (\ils -> text "See also " <> ils <> str ".")
604+ <$> getInlines e
605+ "glossary" -> sect 0
606+ "glossdiv" -> definitionList <$>
607+ mapM parseGlossEntry (filterChildren (named "glossentry") e)
608+ "glosslist" -> definitionList <$>
609+ mapM parseGlossEntry (filterChildren (named "glossentry") e)
605 "chapter" -> sect 0
610 "chapter" -> sect 0
606 "appendix" -> sect 0
611 "appendix" -> sect 0
607 "preface" -> sect 0
612 "preface" -> sect 0
@@ -653,6 +658,7 @@ parseBlock (Elem e) =
653 "info" -> getTitle >> getAuthors >> getDate >> return mempty
658 "info" -> getTitle >> getAuthors >> getDate >> return mempty
654 "articleinfo" -> getTitle >> getAuthors >> getDate >> return mempty
659 "articleinfo" -> getTitle >> getAuthors >> getDate >> return mempty
655 "chapterinfo" -> return mempty -- keywords & other metadata
660 "chapterinfo" -> return mempty -- keywords & other metadata
661+ "glossaryinfo" -> return mempty -- keywords & other metadata
656 "appendixinfo" -> return mempty -- keywords & other metadata
662 "appendixinfo" -> return mempty -- keywords & other metadata
657 "bookinfo" -> getTitle >> getAuthors >> getDate >> return mempty
663 "bookinfo" -> getTitle >> getAuthors >> getDate >> return mempty
658 "article" -> modify (\st -> st{ dbBook = False }) >>
664 "article" -> modify (\st -> st{ dbBook = False }) >>
@@ -673,9 +679,6 @@ parseBlock (Elem e) =
673 x -> x:classes
679 x -> x:classes
674 return $ codeBlockWith (attrValue "id" e, classes', [])
680 return $ codeBlockWith (attrValue "id" e, classes', [])
675 $ trimNl $ strContent e
681 $ trimNl $ strContent e
676− skipWhite (Text (CData _ s _):xs) | all isSpace s = skipWhite xs
677− | otherwise = xs
678− skipWhite xs = xs
679 parseBlockquote = do
682 parseBlockquote = do
680 attrib <- case filterChild (named "attribution") e of
683 attrib <- case filterChild (named "attribution") e of
681 Nothing -> return mempty
684 Nothing -> return mempty
@@ -692,6 +695,12 @@ parseBlock (Elem e) =
692 terms' <- mapM getInlines terms
695 terms' <- mapM getInlines terms
693 items' <- mapM getBlocks items
696 items' <- mapM getBlocks items
694 return (mconcat $ intersperse (str "; ") terms', items')
697 return (mconcat $ intersperse (str "; ") terms', items')
698+ parseGlossEntry e' = do
699+ let terms = filterChildren (named "glossterm") e'
700+ let items = filterChildren (named "glossdef") e'
701+ terms' <- mapM getInlines terms
702+ items' <- mapM getBlocks items
703+ return (mconcat $ intersperse (str "; ") terms', items')
695 getTitle = case filterChild (named "title") e of
704 getTitle = case filterChild (named "title") e of
696 Just t -> do
705 Just t -> do
697 tit <- getInlines t
706 tit <- getInlines t
@@ -761,19 +770,13 @@ parseBlock (Elem e) =
761 parseRow = mapM getBlocks . filterChildren isEntry
770 parseRow = mapM getBlocks . filterChildren isEntry
762 sect n = do isbook <- gets dbBook
771 sect n = do isbook <- gets dbBook
763 let n' = if isbook then n + 1 else n
772 let n' = if isbook then n + 1 else n
764− case skipWhite (elContent e) of
773+ headerText <- case filterChild (named "title") e of
765− ((Elem t):body) | named "title" t -> do
766− h <- header n' <$> (getInlines t)
774+ Just t -> getInlines t
767− modify $ \st -> st{ dbSectionLevel = n }
768− b <- mconcat <$> (mapM parseBlock body)
769− modify $ \st -> st{ dbSectionLevel = n - 1 }
770− return $ h <> b
775+ Nothing -> return mempty
771− body -> do
772− let h = header n' mempty
773− modify $ \st -> st{ dbSectionLevel = n }
776+ modify $ \st -> st{ dbSectionLevel = n }
774− b <- mconcat <$> (mapM parseBlock body)
777+ b <- getBlocks e
775− modify $ \st -> st{ dbSectionLevel = n - 1 }
778+ modify $ \st -> st{ dbSectionLevel = n - 1 }
776− return $ h <> b
779+ return $ header n' headerText <> b
777
780
778getInlines :: Element -> DB Inlines
781getInlines :: Element -> DB Inlines
779getInlines e' = (trimInlines . mconcat) <$> (mapM parseInline $ elContent e')
782getInlines e' = (trimInlines . mconcat) <$> (mapM parseInline $ elContent e')