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.
This commit is contained in:
Mathieu Boespflug 2020-06-14 19:40:00 +02:00 committed by GitHub
parent 7716caaf2a
commit 12a35dd0d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 15 deletions

View file

@ -419,7 +419,7 @@ List of all DocBook tags, with [x] indicating implemented,
elements elements
[x] simplelist - An undecorated list of single words or short phrases [x] simplelist - An undecorated list of single words or short phrases
[ ] simplemsgentry - A wrapper for a simpler entry in a message set [ ] simplemsgentry - A wrapper for a simpler entry in a message set
[ ] simplesect - A section of a document with no subdivisions [x] simplesect - A section of a document with no subdivisions
[ ] spanspec - Formatting information for a spanned column in a table [ ] spanspec - Formatting information for a spanned column in a table
[ ] state - A state or province in an address [ ] state - A state or province in an address
[ ] step - A unit of action in a procedure [ ] step - A unit of action in a procedure
@ -630,8 +630,8 @@ blockTags :: [String]
blockTags = ["toc","index","para","formalpara","simpara", blockTags = ["toc","index","para","formalpara","simpara",
"ackno","epigraph","blockquote","bibliography","bibliodiv", "ackno","epigraph","blockquote","bibliography","bibliodiv",
"biblioentry","glossee","glosseealso","glossary", "biblioentry","glossee","glosseealso","glossary",
"glossdiv","glosslist","chapter","appendix","preface", "glossdiv","glosslist","chapter","appendix","preface","bridgehead",
"bridgehead","sect1","sect2","sect3","sect4","sect5","section", "sect1","sect2","sect3","sect4","sect5","section","simplesect",
"refsect1","refsect2","refsect3","refsection", "qandadiv", "refsect1","refsect2","refsect3","refsection", "qandadiv",
"question","answer","abstract","itemizedlist","orderedlist", "question","answer","abstract","itemizedlist","orderedlist",
"variablelist","article","book","table","informaltable", "variablelist","article","book","table","informaltable",
@ -743,6 +743,9 @@ parseBlock (Elem e) =
"sect4" -> sect 4 "sect4" -> sect 4
"sect5" -> sect 5 "sect5" -> sect 5
"section" -> gets dbSectionLevel >>= sect . (+1) "section" -> gets dbSectionLevel >>= sect . (+1)
"simplesect" ->
gets dbSectionLevel >>=
sectWith (attrValue "id" e,["unnumbered"],[]) . (+1)
"refsect1" -> sect 1 "refsect1" -> sect 1
"refsect2" -> sect 2 "refsect2" -> sect 2
"refsect3" -> sect 3 "refsect3" -> sect 3
@ -904,18 +907,19 @@ parseBlock (Elem e) =
(TableFoot nullAttr []) (TableFoot nullAttr [])
isEntry x = named "entry" x || named "td" x || named "th" x isEntry x = named "entry" x || named "td" x || named "th" x
parseRow = mapM (parseMixed plain . elContent) . filterChildren isEntry parseRow = mapM (parseMixed plain . elContent) . filterChildren isEntry
sect n = do isbook <- gets dbBook sect n = sectWith (attrValue "id" e,[],[]) n
let n' = if isbook || n == 0 then n + 1 else n sectWith attr n = do
headerText <- case filterChild (named "title") e `mplus` isbook <- gets dbBook
(filterChild (named "info") e >>= let n' = if isbook || n == 0 then n + 1 else n
filterChild (named "title")) of headerText <- case filterChild (named "title") e `mplus`
Just t -> getInlines t (filterChild (named "info") e >>=
Nothing -> return mempty filterChild (named "title")) of
modify $ \st -> st{ dbSectionLevel = n } Just t -> getInlines t
b <- getBlocks e Nothing -> return mempty
let ident = attrValue "id" e modify $ \st -> st{ dbSectionLevel = n }
modify $ \st -> st{ dbSectionLevel = n - 1 } b <- getBlocks e
return $ headerWith (ident,[],[]) n' headerText <> b modify $ \st -> st{ dbSectionLevel = n - 1 }
return $ headerWith attr n' headerText <> b
lineItems = mapM getInlines $ filterChildren (named "line") e lineItems = mapM getInlines $ filterChildren (named "line") e
-- | Admonitions are parsed into a div. Following other Docbook tools that output HTML, -- | Admonitions are parsed into a div. Following other Docbook tools that output HTML,
-- we parse the optional title as a div with the @title@ class, and give the -- we parse the optional title as a div with the @title@ class, and give the

View file

@ -47,6 +47,12 @@
<para> <para>
with no blank line with no blank line
</para> </para>
<simplesect>
<title>Level 4</title>
<para>
An unnumbered section.
</para>
</simplesect>
</sect3> </sect3>
</sect2> </sect2>
<sect2 id="level-2"> <sect2 id="level-2">

View file

@ -10,6 +10,8 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Sof
,Header 2 ("level-2-with-emphasis",[],[]) [Str "Level",Space,Str "2",Space,Str "with",Space,Emph [Str "emphasis"]] ,Header 2 ("level-2-with-emphasis",[],[]) [Str "Level",Space,Str "2",Space,Str "with",Space,Emph [Str "emphasis"]]
,Header 3 ("level-3",[],[]) [Str "Level",Space,Str "3"] ,Header 3 ("level-3",[],[]) [Str "Level",Space,Str "3"]
,Para [Str "with",Space,Str "no",Space,Str "blank",Space,Str "line"] ,Para [Str "with",Space,Str "no",Space,Str "blank",Space,Str "line"]
,Header 4 ("",["unnumbered"],[]) [Str "Level",Space,Str "4"]
,Para [Str "An",Space,Str "unnumbered",Space,Str "section."]
,Header 2 ("level-2",[],[]) [Str "Level",Space,Str "2"] ,Header 2 ("level-2",[],[]) [Str "Level",Space,Str "2"]
,Para [Str "with",Space,Str "no",Space,Str "blank",Space,Str "line"] ,Para [Str "with",Space,Str "no",Space,Str "blank",Space,Str "line"]
,Header 1 ("paragraphs",[],[]) [Str "Paragraphs"] ,Header 1 ("paragraphs",[],[]) [Str "Paragraphs"]