git.iko.soy/typeable/pandoc
on master help sign in
RST writer: render Divs with admonition classes as admonitions.

Also omit Div with class "admonition-title". These are generated by the RST reader and should be omitted on round-trip. Closes #4833.

commit919c50162ccc3d7a347a9427ca23887e54e8a333 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 13 Aug 2018, 11:12 (8 years ago) parentc3f17cb
2 files changed+32−3
src/Text/Pandoc/Writers/RST.hs+12−3 test/command/4833.md+20
src/Text/Pandoc/Writers/RST.hs+12−3
@@ -211,12 +211,21 @@ blockToRST :: PandocMonad m
211211 => Block -- ^ Block element
212212 -> RST m Doc
213213blockToRST Null = return empty
214+blockToRST (Div ("",["admonition-title"],[]) _) = return empty
215+ -- this is generated by the rst reader and can safely be
216+ -- omitted when we're generating rst
214217blockToRST (Div (ident,classes,_kvs) bs) = do
215218 contents <- blockListToRST bs
216− let classes' = filter (/= "container") classes
219+ let admonitions = ["attention","caution","danger","error","hint",
220+ "important","note","tip","warning","admonition"]
221+ let admonition = case classes of
222+ (cl:_)
223+ | cl `elem` admonitions
224+ -> ".. " <> text cl <> "::"
225+ cls -> ".. container::" <> space <>
226+ text (unwords (filter (/= "container") cls))
217227 return $ blankline $$
218− (".. container::" <> space <>
219− text (unwords classes')) $$
228+ admonition $$
220229 (if null ident
221230 then blankline
222231 else " :name: " <> text ident $$ blankline) $$
test/command/4833.mdnew file+20
@@ -0,0 +1,20 @@
1+```
2+pandoc -f native -t rst
3+[Div ("",["warning"],[])
4+ [Div ("",["admonition-title"],[])
5+ [Para [Str "Warning"]]
6+ ,Para [Str "Hi"]]]
7+^D
8+.. warning::
9+
10+ Hi
11+```
12+```
13+pandoc -f native -t rst
14+[Div ("",["unknown"],[])
15+ [Para [Str "Hi"]]]
16+^D
17+.. container:: unknown
18+
19+ Hi
20+```