Skip to content

Commit f72548a

Browse files
committed
DocBook reader: Handle title inside orderedlist.
Also some other elements that allow title: blockquote, calloutlist, etc. Closes #10594.
1 parent b8c2d99 commit f72548a

File tree

2 files changed

+55
-15
lines changed

2 files changed

+55
-15
lines changed

src/Text/Pandoc/Readers/DocBook.hs

+27-15
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ parseBlock (Elem e) =
866866
"simpara" -> parseMixed para (elContent e)
867867
"ackno" -> parseMixed para (elContent e)
868868
"epigraph" -> parseBlockquote
869-
"blockquote" -> parseBlockquote
869+
"blockquote" -> withOptionalTitle parseBlockquote
870870
"attribution" -> skip
871871
"titleabbrev" -> skip
872872
"authorinitials" -> skip
@@ -917,9 +917,10 @@ parseBlock (Elem e) =
917917
"question" -> addToStart (strong (str "Q:") <> str " ") <$> getBlocks e
918918
"answer" -> addToStart (strong (str "A:") <> str " ") <$> getBlocks e
919919
"abstract" -> blockQuote <$> getBlocks e
920-
"calloutlist" -> bulletList <$> callouts
921-
"itemizedlist" -> bulletList . handleCompact <$> listitems
922-
"orderedlist" -> do
920+
"calloutlist" -> withOptionalTitle $ bulletList <$> callouts
921+
"itemizedlist" -> withOptionalTitle $
922+
bulletList . handleCompact <$> listitems
923+
"orderedlist" -> withOptionalTitle $ do
923924
let listStyle = case attrValue "numeration" e of
924925
"arabic" -> Decimal
925926
"loweralpha" -> LowerAlpha
@@ -1106,23 +1107,34 @@ parseBlock (Elem e) =
11061107
Just t -> Just ("titleabbrev", strContentRecursive t)
11071108
Nothing -> Nothing
11081109
lineItems = mapM getInlines $ filterChildren (named "line") e
1110+
1111+
-- <title> elements can be directly nested inside an admonition block, use
1112+
-- it if it's there. It is unclear whether we should include the label in
1113+
-- the title: docbook references are ambiguous on that, and some implementations of admonitions
1114+
-- (e.g. asciidoctor) just use an icon in all cases. To be conservative, we don't
1115+
-- include the label and leave it to styling.
1116+
--
1117+
getTitle = case filterChild (named "title") e of
1118+
Just t -> Just <$> getInlines t
1119+
Nothing -> return Nothing
1120+
withOptionalTitle p = do
1121+
mbt <- getTitle
1122+
b <- p
1123+
case mbt of
1124+
Nothing -> return b
1125+
Just t -> return $ divWith (attrValue "id" e,[],[])
1126+
(divWith ("", ["title"], []) (plain t) <> b)
1127+
11091128
-- Admonitions are parsed into a div. Following other Docbook tools that output HTML,
11101129
-- we parse the optional title as a div with the @title@ class, and give the
11111130
-- block itself a class corresponding to the admonition name.
11121131
parseAdmonition label = do
1113-
-- <title> elements can be directly nested inside an admonition block, use
1114-
-- it if it's there. It is unclear whether we should include the label in
1115-
-- the title: docbook references are ambiguous on that, and some implementations of admonitions
1116-
-- (e.g. asciidoctor) just use an icon in all cases. To be conservative, we don't
1117-
-- include the label and leave it to styling.
1118-
title <- divWith ("", ["title"], []) . plain <$>
1119-
case filterChild (named "title") e of
1120-
Just t -> getInlines t
1121-
Nothing -> return mempty
1122-
-- this will ignore the title element if it is present
1132+
mbt <- getTitle
1133+
-- this will ignore the title element if it is present:
11231134
b <- getBlocks e
1135+
let t = divWith ("", ["title"], []) (plain $ fromMaybe mempty mbt)
11241136
-- we also attach the label as a class, so it can be styled properly
1125-
return $ divWith (attrValue "id" e,[label],[]) (title <> b)
1137+
return $ divWith (attrValue "id" e,[label],[]) (t <> b)
11261138

11271139
toAlignment :: Element -> Alignment
11281140
toAlignment c = case findAttr (unqual "align") c of

test/command/10594.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
```
2+
% pandoc -f docbook -t native
3+
<orderedlist numeration="loweralpha">
4+
<title>header inside listing</title> // not rendered in any output format!
5+
<listitem>
6+
<simpara>first step</simpara>
7+
</listitem>
8+
</orderedlist>
9+
^D
10+
[ Div
11+
( "" , [] , [] )
12+
[ Div
13+
( "" , [ "title" ] , [] )
14+
[ Plain
15+
[ Str "header"
16+
, Space
17+
, Str "inside"
18+
, Space
19+
, Str "listing"
20+
]
21+
]
22+
, OrderedList
23+
( 1 , LowerAlpha , DefaultDelim )
24+
[ [ Para [ Str "first" , Space , Str "step" ] ] ]
25+
]
26+
]
27+
28+
```

0 commit comments

Comments
 (0)