DocBook reader: omit empty title when not required.

Closes #11422.

This affects example and sidebar elements.
This commit is contained in:
John MacFarlane
2026-01-27 10:20:31 +01:00
parent 675e0c4506
commit 8191d06aff
2 changed files with 21 additions and 6 deletions
+9 -6
View File
@@ -173,7 +173,7 @@ List of all DocBook tags, with [x] indicating implemented,
[ ] errorname - An error name
[ ] errortext - An error message.
[ ] errortype - The classification of an error message
[ ] example - A formal example, with a title
[x] example - A formal example, with a title
[ ] exceptionname - The name of an exception
[ ] fax - A fax number
[ ] fieldsynopsis - The name of a field in a class definition
@@ -438,7 +438,7 @@ List of all DocBook tags, with [x] indicating implemented,
[ ] shortaffil - A brief description of an affiliation
[ ] shortcut - A key combination for an action that is also accessible through
a menu
[ ] sidebar - A portion of a document that is isolated from the main
[x] sidebar - A portion of a document that is isolated from the main
narrative flow
[ ] sidebarinfo - Meta-information for a Sidebar
[x] simpara - A paragraph that contains only text and inline markup, no block
@@ -919,8 +919,8 @@ parseBlock (Elem e) = do
"refsect2" -> sect 2
"refsect3" -> sect 3
"refsection" -> gets dbSectionLevel >>= sect . (+1)
l | l `elem` titledBlockElements -> parseAdmonition l
l | l `elem` admonitionTags -> parseAdmonition l
l | l `elem` titledBlockElements -> parseAdmonition False l
l | l `elem` admonitionTags -> parseAdmonition True l
"area" -> skip
"areaset" -> skip
"areaspec" -> skip
@@ -1152,11 +1152,14 @@ parseBlock (Elem e) = do
-- 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
-- block itself a class corresponding to the admonition name.
parseAdmonition label = do
parseAdmonition alwaysIncludeTitle label = do
mbt <- getTitle
-- this will ignore the title element if it is present:
b <- getBlocks e
let t = divWith ("", ["title"], []) (plain $ fromMaybe mempty mbt)
let t = maybe mempty (divWith ("", ["title"], []) . plain)
(case mbt of
Nothing | alwaysIncludeTitle -> Just mempty
_ -> mbt)
-- we also attach the label as a class, so it can be styled properly
return $ divWith (attrValue "id" e,[label],[]) (t <> b)
+12
View File
@@ -0,0 +1,12 @@
```
% pandoc -f docbook -t markdown
<example>
<para>
Example without a title.
</para>
</example>
^D
::: example
Example without a title.
:::
```