DocBook reader: handle <part>.

Closes #8712.
This commit is contained in:
John MacFarlane
2023-03-21 19:06:04 -07:00
parent 0883efd145
commit 4ea0508e68
+16 -3
View File
@@ -44,11 +44,12 @@ import Text.Pandoc.Builder
import Text.Pandoc.Class.PandocMonad (PandocMonad, report) import Text.Pandoc.Class.PandocMonad (PandocMonad, report)
import Text.Pandoc.Options import Text.Pandoc.Options
import Text.Pandoc.Logging (LogMessage(..)) import Text.Pandoc.Logging (LogMessage(..))
import Text.Pandoc.Shared (safeRead, extractSpaces) import Text.Pandoc.Shared (safeRead, extractSpaces, headerShift)
import Text.Pandoc.Sources (ToSources(..), sourcesToText) import Text.Pandoc.Sources (ToSources(..), sourcesToText)
import Text.TeXMath (readMathML, writeTeX) import Text.TeXMath (readMathML, writeTeX)
import qualified Data.Map as M import qualified Data.Map as M
import Text.Pandoc.XML.Light import Text.Pandoc.XML.Light
import Text.Pandoc.Walk (query)
{- {-
@@ -320,7 +321,7 @@ List of all DocBook tags, with [x] indicating implemented,
[x] para - A paragraph [x] para - A paragraph
[ ] paramdef - Information about a function parameter in a programming language [ ] paramdef - Information about a function parameter in a programming language
[x] parameter - A value or a symbolic reference to a value [x] parameter - A value or a symbolic reference to a value
[ ] part - A division in a book [x] part - A division in a book
[ ] partinfo - Meta-information for a Part [ ] partinfo - Meta-information for a Part
[ ] partintro - An introduction to the contents of a part [ ] partintro - An introduction to the contents of a part
[ ] personblurb - A short description or note about a person [ ] personblurb - A short description or note about a person
@@ -563,7 +564,14 @@ readDocBook _ inp = do
docbookEntityMap docbookEntityMap
(TL.fromStrict . handleInstructions . sourcesToText $ sources) (TL.fromStrict . handleInstructions . sourcesToText $ sources)
(bs, st') <- flip runStateT (def{ dbContent = tree }) $ mapM parseBlock tree (bs, st') <- flip runStateT (def{ dbContent = tree }) $ mapM parseBlock tree
return $ Pandoc (dbMeta st') (toList . mconcat $ bs) let headerLevel (Header n _ _) = [n]
headerLevel _ = []
let bottomLevel = maybe 1 minimum $ nonEmpty $ query headerLevel bs
return $
-- handle the case where you have <part> or <chapter>
(if bottomLevel < 1
then headerShift (1 - bottomLevel)
else id) $ Pandoc (dbMeta st') $ toList $ mconcat bs
-- We treat certain processing instructions by converting them to tags -- We treat certain processing instructions by converting them to tags
-- beginning "pi-". -- beginning "pi-".
@@ -746,6 +754,8 @@ blockTags = Set.fromList $
, "mediaobject" , "mediaobject"
, "orderedlist" , "orderedlist"
, "para" , "para"
, "part"
, "partinfo"
, "preface" , "preface"
, "procedure" , "procedure"
, "programlisting" , "programlisting"
@@ -882,6 +892,7 @@ parseBlock (Elem e) =
"glosslist" -> definitionList <$> "glosslist" -> definitionList <$>
mapM parseGlossEntry (filterChildren (named "glossentry") e) mapM parseGlossEntry (filterChildren (named "glossentry") e)
"chapter" -> modify (\st -> st{ dbBook = True}) >> sect 0 "chapter" -> modify (\st -> st{ dbBook = True}) >> sect 0
"part" -> modify (\st -> st{ dbBook = True}) >> sect (-1)
"appendix" -> sect 0 "appendix" -> sect 0
"preface" -> sect 0 "preface" -> sect 0
"bridgehead" -> para . strong <$> getInlines e "bridgehead" -> para . strong <$> getInlines e
@@ -940,6 +951,7 @@ parseBlock (Elem e) =
"sect4info" -> skip -- keywords & other metadata "sect4info" -> skip -- keywords & other metadata
"sect5info" -> skip -- keywords & other metadata "sect5info" -> skip -- keywords & other metadata
"chapterinfo" -> skip -- keywords & other metadata "chapterinfo" -> skip -- keywords & other metadata
"partinfo" -> skip -- keywords & other metadata
"glossaryinfo" -> skip -- keywords & other metadata "glossaryinfo" -> skip -- keywords & other metadata
"appendixinfo" -> skip -- keywords & other metadata "appendixinfo" -> skip -- keywords & other metadata
"bookinfo" -> addMetadataFromElement e "bookinfo" -> addMetadataFromElement e
@@ -1342,6 +1354,7 @@ parseInline (Elem e) =
xrefTitleByElem el xrefTitleByElem el
| not (T.null xrefLabel) = xrefLabel | not (T.null xrefLabel) = xrefLabel
| otherwise = case qName (elName el) of | otherwise = case qName (elName el) of
"part" -> descendantContent "title" el
"chapter" -> descendantContent "title" el "chapter" -> descendantContent "title" el
"section" -> descendantContent "title" el "section" -> descendantContent "title" el
"sect1" -> descendantContent "title" el "sect1" -> descendantContent "title" el