git.iko.soy/typeable/pandoc
on master help sign in
Docbook: map <simplesect> to unnumbered section (#6436)

A <simplesect> is a section like any other, except that it never contains an subsection, and is typically rendered unnumbered.

commit12a35dd0d0f7363ad5b85ab859925113c65aa61f authorMathieu Boespflug <m@tweag.io> dateSun 14 Jun 2020, 19:40 (6 years ago) parent7716caa
3 files changed+27−15
src/Text/Pandoc/Readers/DocBook.hs+19−15 test/docbook-reader.docbook+6 test/docbook-reader.native+2
src/Text/Pandoc/Readers/DocBook.hs+19−15
@@ -419,7 +419,7 @@ List of all DocBook tags, with [x] indicating implemented,
419419 elements
420420[x] simplelist - An undecorated list of single words or short phrases
421421[ ] simplemsgentry - A wrapper for a simpler entry in a message set
422−[ ] simplesect - A section of a document with no subdivisions
422+[x] simplesect - A section of a document with no subdivisions
423423[ ] spanspec - Formatting information for a spanned column in a table
424424[ ] state - A state or province in an address
425425[ ] step - A unit of action in a procedure
@@ -630,8 +630,8 @@ blockTags :: [String]
630630blockTags = ["toc","index","para","formalpara","simpara",
631631 "ackno","epigraph","blockquote","bibliography","bibliodiv",
632632 "biblioentry","glossee","glosseealso","glossary",
633− "glossdiv","glosslist","chapter","appendix","preface",
634− "bridgehead","sect1","sect2","sect3","sect4","sect5","section",
633+ "glossdiv","glosslist","chapter","appendix","preface","bridgehead",
634+ "sect1","sect2","sect3","sect4","sect5","section","simplesect",
635635 "refsect1","refsect2","refsect3","refsection", "qandadiv",
636636 "question","answer","abstract","itemizedlist","orderedlist",
637637 "variablelist","article","book","table","informaltable",
@@ -743,6 +743,9 @@ parseBlock (Elem e) =
743743 "sect4" -> sect 4
744744 "sect5" -> sect 5
745745 "section" -> gets dbSectionLevel >>= sect . (+1)
746+ "simplesect" ->
747+ gets dbSectionLevel >>=
748+ sectWith (attrValue "id" e,["unnumbered"],[]) . (+1)
746749 "refsect1" -> sect 1
747750 "refsect2" -> sect 2
748751 "refsect3" -> sect 3
@@ -904,18 +907,19 @@ parseBlock (Elem e) =
904907 (TableFoot nullAttr [])
905908 isEntry x = named "entry" x || named "td" x || named "th" x
906909 parseRow = mapM (parseMixed plain . elContent) . filterChildren isEntry
907− sect n = do isbook <- gets dbBook
908− let n' = if isbook || n == 0 then n + 1 else n
909− headerText <- case filterChild (named "title") e `mplus`
910− (filterChild (named "info") e >>=
911− filterChild (named "title")) of
912− Just t -> getInlines t
913− Nothing -> return mempty
914− modify $ \st -> st{ dbSectionLevel = n }
915− b <- getBlocks e
916− let ident = attrValue "id" e
917− modify $ \st -> st{ dbSectionLevel = n - 1 }
918− return $ headerWith (ident,[],[]) n' headerText <> b
910+ sect n = sectWith (attrValue "id" e,[],[]) n
911+ sectWith attr n = do
912+ isbook <- gets dbBook
913+ let n' = if isbook || n == 0 then n + 1 else n
914+ headerText <- case filterChild (named "title") e `mplus`
915+ (filterChild (named "info") e >>=
916+ filterChild (named "title")) of
917+ Just t -> getInlines t
918+ Nothing -> return mempty
919+ modify $ \st -> st{ dbSectionLevel = n }
920+ b <- getBlocks e
921+ modify $ \st -> st{ dbSectionLevel = n - 1 }
922+ return $ headerWith attr n' headerText <> b
919923 lineItems = mapM getInlines $ filterChildren (named "line") e
920924 -- | Admonitions are parsed into a div. Following other Docbook tools that output HTML,
921925 -- we parse the optional title as a div with the @title@ class, and give the
test/docbook-reader.docbook+6
@@ -47,6 +47,12 @@
4747 <para>
4848 with no blank line
4949 </para>
50+ <simplesect>
51+ <title>Level 4</title>
52+ <para>
53+ An unnumbered section.
54+ </para>
55+ </simplesect>
5056 </sect3>
5157 </sect2>
5258 <sect2 id="level-2">
test/docbook-reader.native+2
@@ -10,6 +10,8 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Sof
1010,Header 2 ("level-2-with-emphasis",[],[]) [Str "Level",Space,Str "2",Space,Str "with",Space,Emph [Str "emphasis"]]
1111,Header 3 ("level-3",[],[]) [Str "Level",Space,Str "3"]
1212,Para [Str "with",Space,Str "no",Space,Str "blank",Space,Str "line"]
13+,Header 4 ("",["unnumbered"],[]) [Str "Level",Space,Str "4"]
14+,Para [Str "An",Space,Str "unnumbered",Space,Str "section."]
1315,Header 2 ("level-2",[],[]) [Str "Level",Space,Str "2"]
1416,Para [Str "with",Space,Str "no",Space,Str "blank",Space,Str "line"]
1517,Header 1 ("paragraphs",[],[]) [Str "Paragraphs"]