diff options
author | John MacFarlane <jgm@berkeley.edu> | 2021-10-27 12:06:29 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2021-10-27 12:50:51 -0700 |
commit | 25a86fc06fd5d7e07251ca9bd758cc42c4234d70 (patch) | |
tree | e94963824ac7ae69bf74b3ba5c5d0d2277ead467 /src | |
parent | 26a8de684ea8ec2ed0e2edebda78a8673c2c62d8 (diff) | |
download | pandoc-25a86fc06fd5d7e07251ca9bd758cc42c4234d70.tar.gz |
Markdown writer: Be sure to quote special values in YAML metadata.
E.g. "Y", "yes", which are now (with yaml library) considered
boolean values, as well as "null".
This fixes a bug with roundtripping markdown -> markdown:
```
---
foo: "true"
...
```
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Writers/Markdown.hs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index f03dc375d..4f6a8bfb1 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -140,10 +140,20 @@ valToYaml (SimpleVal x) | otherwise = if hasNewlines x then hang 0 ("|" <> cr) x - else if isNothing $ foldM needsDoubleQuotes True x - then "\"" <> fmap escapeInDoubleQuotes x <> "\"" - else x + else case x of + Text _ t | isSpecialString t -> + "\"" <> fmap escapeInDoubleQuotes x <> "\"" + _ | isNothing (foldM needsDoubleQuotes True x) -> + "\"" <> fmap escapeInDoubleQuotes x <> "\"" + | otherwise -> x where + isSpecialString t = Set.member t specialStrings + specialStrings = Set.fromList + ["y", "Y", "yes", "Yes", "YES", "n", "N", + "no", "No", "NO", "true", "True", "TRUE", + "false", "False", "FALSE", "on", "On", "ON", + "off", "Off", "OFF", "null", "Null", + "NULL", "~", "*"] needsDoubleQuotes isFirst t = if T.any isBadAnywhere t || (isFirst && T.any isYamlPunct (T.take 1 t)) |