mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-01 15:38:09 +08:00
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:
@@ -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
|
||||
|
||||
@@ -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" ]
|
||||
]
|
||||
]
|
||||
```
|
||||
Reference in New Issue
Block a user