git.iko.soy/typeable/pandoc
on master help sign in
DocBook reader: Implemented glossary, simplified sect.
commit023bb2bb458f1c34d1cea0c44346cf12aceee792 authorJohn MacFarlane <fiddlosopher@gmail.com> dateThu 10 May 2012, 21:27 (14 years ago) parent523acad
1 file changed+34−31
src/Text/Pandoc/Readers/DocBook.hs+34−31
src/Text/Pandoc/Readers/DocBook.hs+34−31
@@ -150,15 +150,15 @@ List of all DocBook tags, with [x] indicating implemented,
150150[ ] funcsynopsisinfo - Information supplementing the FuncDefs of a FuncSynopsis
151151[x] function - The name of a function or subroutine, as in a
152152 programming language
153−[ ] glossary - A glossary
154−[ ] glossaryinfo - Meta-information for a Glossary
155−[ ] glossdef - A definition in a GlossEntry
156−[ ] glossdiv - A division in a Glossary
157−[ ] glossentry - An entry in a Glossary or GlossList
158−[ ] glosslist - A wrapper for a set of GlossEntrys
159−[ ] glosssee - A cross-reference from one GlossEntry to another
160−[ ] glossseealso - A cross-reference from one GlossEntry to another
161−[ ] glossterm - A glossary term
153+[x] glossary - A glossary
154+[x] glossaryinfo - Meta-information for a Glossary
155+[x] glossdef - A definition in a GlossEntry
156+[x] glossdiv - A division in a Glossary
157+[x] glossentry - An entry in a Glossary or GlossList
158+[x] glosslist - A wrapper for a set of GlossEntrys
159+[x] glosssee - A cross-reference from one GlossEntry to another
160+[x] glossseealso - A cross-reference from one GlossEntry to another
161+[x] glossterm - A glossary term
162162[ ] graphic - A displayed graphical object (not an inline)
163163[ ] graphicco - A graphic that contains callout areas
164164[ ] group - A group of elements in a CmdSynopsis
@@ -595,13 +595,18 @@ parseBlock (Elem e) =
595595 "titleabbrev" -> return mempty
596596 "authorinitials" -> return mempty
597597 "title" -> return mempty -- handled by getTitle or sect
598− "bibliography" -> do
599− book <- gets dbBook
600− if book then sect 0 else sect 1
601− "bibliodiv" -> do
602− book <- gets dbBook
603− if book then sect 1 else sect 2
598+ "bibliography" -> sect 0
599+ "bibliodiv" -> sect 1
604600 "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)
605610 "chapter" -> sect 0
606611 "appendix" -> sect 0
607612 "preface" -> sect 0
@@ -653,6 +658,7 @@ parseBlock (Elem e) =
653658 "info" -> getTitle >> getAuthors >> getDate >> return mempty
654659 "articleinfo" -> getTitle >> getAuthors >> getDate >> return mempty
655660 "chapterinfo" -> return mempty -- keywords & other metadata
661+ "glossaryinfo" -> return mempty -- keywords & other metadata
656662 "appendixinfo" -> return mempty -- keywords & other metadata
657663 "bookinfo" -> getTitle >> getAuthors >> getDate >> return mempty
658664 "article" -> modify (\st -> st{ dbBook = False }) >>
@@ -673,9 +679,6 @@ parseBlock (Elem e) =
673679 x -> x:classes
674680 return $ codeBlockWith (attrValue "id" e, classes', [])
675681 $ trimNl $ strContent e
676− skipWhite (Text (CData _ s _):xs) | all isSpace s = skipWhite xs
677− | otherwise = xs
678− skipWhite xs = xs
679682 parseBlockquote = do
680683 attrib <- case filterChild (named "attribution") e of
681684 Nothing -> return mempty
@@ -692,6 +695,12 @@ parseBlock (Elem e) =
692695 terms' <- mapM getInlines terms
693696 items' <- mapM getBlocks items
694697 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')
695704 getTitle = case filterChild (named "title") e of
696705 Just t -> do
697706 tit <- getInlines t
@@ -761,19 +770,13 @@ parseBlock (Elem e) =
761770 parseRow = mapM getBlocks . filterChildren isEntry
762771 sect n = do isbook <- gets dbBook
763772 let n' = if isbook then n + 1 else n
764− case skipWhite (elContent e) of
765− ((Elem t):body) | named "title" t -> do
766− h <- header n' <$> (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
771− body -> do
772− let h = header n' mempty
773− modify $ \st -> st{ dbSectionLevel = n }
774− b <- mconcat <$> (mapM parseBlock body)
775− modify $ \st -> st{ dbSectionLevel = n - 1 }
776− return $ h <> b
773+ headerText <- case filterChild (named "title") e of
774+ Just t -> getInlines t
775+ Nothing -> return mempty
776+ modify $ \st -> st{ dbSectionLevel = n }
777+ b <- getBlocks e
778+ modify $ \st -> st{ dbSectionLevel = n - 1 }
779+ return $ header n' headerText <> b
777780
778781getInlines :: Element -> DB Inlines
779782getInlines e' = (trimInlines . mconcat) <$> (mapM parseInline $ elContent e')