DocBook reader: better handle formalpara, example, and sidebar.

Include identifiers and titles in each case.

The code should be credited to @tombolano.

Closes #8666.
This commit is contained in:
John MacFarlane
2025-02-01 17:04:38 -08:00
parent c0dc953825
commit 1470b3a573
2 changed files with 45 additions and 6 deletions
+5 -6
View File
@@ -797,6 +797,9 @@ blockTags = Set.fromList $
admonitionTags :: [Text]
admonitionTags = ["caution","danger","important","note","tip","warning"]
titledBlockElements :: [Text]
titledBlockElements = ["example", "formalpara", "sidebar"]
-- Trim leading and trailing newline characters
trimNl :: Text -> Text
trimNl = T.dropAround (== '\n')
@@ -860,12 +863,6 @@ parseBlock (Elem e) =
"toc" -> skip -- skip TOC, since in pandoc it's autogenerated
"index" -> skip -- skip index, since page numbers meaningless
"para" -> parseMixed para (elContent e)
"formalpara" -> do
tit <- case filterChild (named "title") e of
Just t -> divWith ("",["formalpara-title"],[]) .
para . strong <$> getInlines t
Nothing -> return mempty
(tit <>) <$> parseMixed para (elContent e)
"simpara" -> parseMixed para (elContent e)
"ackno" -> parseMixed para (elContent e)
"epigraph" -> parseBlockquote
@@ -910,6 +907,7 @@ parseBlock (Elem e) =
"refsect2" -> sect 2
"refsect3" -> sect 3
"refsection" -> gets dbSectionLevel >>= sect . (+1)
l | l `elem` titledBlockElements -> parseAdmonition l
l | l `elem` admonitionTags -> parseAdmonition l
"area" -> skip
"areaset" -> skip
@@ -981,6 +979,7 @@ parseBlock (Elem e) =
lift $ report $ IgnoredElement name
return mempty
compactSpacing = case attrValue "spacing" e of
"compact" -> True
_ -> False
+40
View File
@@ -0,0 +1,40 @@
```
% pandoc -f docbook -t native
<formalpara xml:id="my_code_id">
<title>Code title</title>
<para>
<programlisting language="bash" linenumbering="unnumbered">echo "hello world!"</programlisting>
</para>
</formalpara>
<example xml:id="my_example_id">
<title>Example title</title>
<simpara>example content</simpara>
</example>
<sidebar xml:id="my_sidebar_id">
<title>Sidebar title</title>
<simpara>sidebar content</simpara>
</sidebar>
^D
[ Div
( "my_code_id" , [ "formalpara" ] , [] )
[ Div
( "" , [ "title" ] , [] )
[ Plain [ Str "Code" , Space , Str "title" ] ]
, CodeBlock ( "" , [ "bash" ] , [] ) "echo \"hello world!\""
]
, Div
( "my_example_id" , [ "example" ] , [] )
[ Div
( "" , [ "title" ] , [] )
[ Plain [ Str "Example" , Space , Str "title" ] ]
, Para [ Str "example" , Space , Str "content" ]
]
, Div
( "my_sidebar_id" , [ "sidebar" ] , [] )
[ Div
( "" , [ "title" ] , [] )
[ Plain [ Str "Sidebar" , Space , Str "title" ] ]
, Para [ Str "sidebar" , Space , Str "content" ]
]
]
```