Properly escape attributes in Markdown writer.

Closes #5369.
This commit is contained in:
John MacFarlane
2019-03-17 18:08:57 -07:00
parent ebd7035a2a
commit 3880a23de9
2 changed files with 16 additions and 4 deletions
+9 -4
View File
@@ -306,17 +306,22 @@ attrsToMarkdown :: Attr -> Doc
attrsToMarkdown attribs = braces $ hsep [attribId, attribClasses, attribKeys]
where attribId = case attribs of
([],_,_) -> empty
(i,_,_) -> "#" <> text i
(i,_,_) -> "#" <> escAttr i
attribClasses = case attribs of
(_,[],_) -> empty
(_,cs,_) -> hsep $
map (text . ('.':))
map (escAttr . ('.':))
cs
attribKeys = case attribs of
(_,_,[]) -> empty
(_,_,ks) -> hsep $
map (\(k,v) -> text k
<> "=\"" <> text v <> "\"") ks
map (\(k,v) -> escAttr k
<> "=\"" <>
escAttr v <> "\"") ks
escAttr = mconcat . map escAttrChar
escAttrChar '"' = text "\\\""
escAttrChar '\\' = text "\\\\"
escAttrChar c = text [c]
linkAttributes :: WriterOptions -> Attr -> Doc
linkAttributes opts attr =
+7
View File
@@ -0,0 +1,7 @@
```
% pandoc -f native -t markdown
[Div ("",[],[("tags","[\"o\\ne\",\"two\"]")]) [] ]
^D
::: {tags="[\"o\\ne\",\"two\"]"}
:::
```