aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-03-17 18:08:57 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2019-03-17 18:15:47 -0700
commit3880a23de9004748319bdf3ecced676d6e5b2ea0 (patch)
treec5174f6c24db2a134d182f032b0688ecf65067d2 /src/Text/Pandoc
parentebd7035a2a239b3dc845e518a9db9fc6a5181449 (diff)
downloadpandoc-3880a23de9004748319bdf3ecced676d6e5b2ea0.tar.gz
Properly escape attributes in Markdown writer.
Closes #5369.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index 1a651e57f..4964fbad0 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -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 =