git.iko.soy/typeable/pandoc
on master help sign in
Docbook writer: Handle admonition titles from Markdown reader

Docbook reader produces a `Div` with `title` class for `<title>` element within an “admonition” element. Markdown writer then turns this into a fenced div with `title` class attribute. Since fenced divs are block elements, their content is recognized as a paragraph by the Markdown reader. This is an issue for Docbook writer because it would produce an invalid DocBook document from such AST – the `<title>` element can only contain “inline” elements. Let’s handle this invalid special case separately by unwrapping the paragraph before creating the `<title>` element.

commit70c7c5703afcbd1cbf2a80c2be515e038abcd419 authorJan Tojnar <jtojnar@gmail.com> dateMon 7 Dec 2020, 07:28 (6 years ago) parent16ef877
2 files changed+16
src/Text/Pandoc/Writers/Docbook.hs+2 test/Tests/Writers/Docbook.hs+14
src/Text/Pandoc/Writers/Docbook.hs+2
@@ -201,6 +201,8 @@ blockToDocbook opts (Div (ident,classes,_) bs) = do
201201 (l:_) | l `elem` admonitions -> do
202202 let (mTitleBs, bodyBs) =
203203 case bs of
204+ -- Matches AST produced by the DocBook reader → Markdown writer → Markdown reader chain.
205+ (Div (_,["title"],_) [Para ts] : rest) -> (Just (inlinesToDocbook opts ts), rest)
204206 -- Matches AST produced by the Docbook reader.
205207 (Div (_,["title"],_) ts : rest) -> (Just (blocksToDocbook opts ts), rest)
206208 _ -> (Nothing, bs)
test/Tests/Writers/Docbook.hs+14
@@ -93,6 +93,20 @@ tests = [ testGroup "line blocks"
9393 , " </para>"
9494 , "</attention>"
9595 ]
96+ , "admonition-with-title-in-para" =:
97+ divWith ("foo", ["attention"], []) (
98+ divWith ("foo", ["title"], [])
99+ (para "This is title") <>
100+ para "This is a test"
101+ )
102+ =?> unlines
103+ [ "<attention id=\"foo\">"
104+ , " <title>This is title</title>"
105+ , " <para>"
106+ , " This is a test"
107+ , " </para>"
108+ , "</attention>"
109+ ]
96110 , "single-child" =:
97111 divWith ("foo", [], []) (para "This is a test")
98112 =?> unlines