git.iko.soy/typeable/pandoc
on master help sign in
Properly escape attributes in Markdown writer.
3880a23John MacFarlane
src/Text/Pandoc/Writers/Markdown.hs+9−4
@@ -306,17 +306,22 @@ attrsToMarkdown :: Attr -> Doc
306attrsToMarkdown attribs = braces $ hsep [attribId, attribClasses, attribKeys]
306attrsToMarkdown attribs = braces $ hsep [attribId, attribClasses, attribKeys]
307 where attribId = case attribs of
307 where attribId = case attribs of
308 ([],_,_) -> empty
308 ([],_,_) -> empty
309− (i,_,_) -> "#" <> text i
309+ (i,_,_) -> "#" <> escAttr i
310 attribClasses = case attribs of
310 attribClasses = case attribs of
311 (_,[],_) -> empty
311 (_,[],_) -> empty
312 (_,cs,_) -> hsep $
312 (_,cs,_) -> hsep $
313− map (text . ('.':))
313+ map (escAttr . ('.':))
314 cs
314 cs
315 attribKeys = case attribs of
315 attribKeys = case attribs of
316 (_,_,[]) -> empty
316 (_,_,[]) -> empty
317 (_,_,ks) -> hsep $
317 (_,_,ks) -> hsep $
318− map (\(k,v) -> text k
318+ map (\(k,v) -> escAttr k
319− <> "=\"" <> text v <> "\"") ks
319+ <> "=\"" <>
320+ escAttr v <> "\"") ks
321+ escAttr = mconcat . map escAttrChar
322+ escAttrChar '"' = text "\\\""
323+ escAttrChar '\\' = text "\\\\"
324+ escAttrChar c = text [c]
320
325
321linkAttributes :: WriterOptions -> Attr -> Doc
326linkAttributes :: WriterOptions -> Attr -> Doc
322linkAttributes opts attr =
327linkAttributes opts attr =
test/command/5369.mdnew file+7
@@ -0,0 +1,7 @@
1+```
2+% pandoc -f native -t markdown
3+[Div ("",[],[("tags","[\"o\\ne\",\"two\"]")]) [] ]
4+^D
5+::: {tags="[\"o\\ne\",\"two\"]"}
6+:::
7+```