diff options
author | John MacFarlane <jgm@berkeley.edu> | 2018-12-31 21:20:56 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2018-12-31 21:20:56 -0800 |
commit | ffc2192caffd101666dd6c793631798d7f22878f (patch) | |
tree | 88599027ece92d959f9a197c96cea800f1182936 | |
parent | c8b79b0a04c113e0ea41099b0201576710158a49 (diff) | |
download | pandoc-ffc2192caffd101666dd6c793631798d7f22878f.tar.gz |
Simplify/fix reading of `--metadata` values on command line.
Previously we used HsYAML's decodeStrict to recognize
boolean values (treating everything else as a string).
This caused problems relating to hvr/HsYAML#7.
We now just check for the recognized boolean values
`true|True|TRUE|false|False|FALSE`, and avoid using
HsYAML.
Closes #5177.
-rw-r--r-- | src/Text/Pandoc/App.hs | 15 | ||||
-rw-r--r-- | test/command/5177.md | 12 |
2 files changed, 20 insertions, 7 deletions
diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs index 6b320df12..7faac2b00 100644 --- a/src/Text/Pandoc/App.hs +++ b/src/Text/Pandoc/App.hs @@ -55,7 +55,6 @@ import qualified Data.Text.Lazy as TL import qualified Data.Text.Lazy.Encoding as TE import qualified Data.Text.Encoding.Error as TE import qualified Data.Text.Encoding.Error as TSE -import qualified Data.YAML as YAML import Network.URI (URI (..), parseURI) import System.Directory (getAppUserDataDirectory) import System.Exit (exitSuccess) @@ -332,12 +331,14 @@ removeMetaKeys :: [(String,String)] -> Pandoc -> Pandoc removeMetaKeys kvs pdc = foldr (deleteMeta . fst) pdc kvs readMetaValue :: String -> MetaValue -readMetaValue s = case YAML.decodeStrict (UTF8.fromString s) of - Right [YAML.Scalar (YAML.SStr t)] - -> MetaString $ T.unpack t - Right [YAML.Scalar (YAML.SBool b)] - -> MetaBool b - _ -> MetaString s +readMetaValue s + | s == "true" = MetaBool True + | s == "True" = MetaBool True + | s == "TRUE" = MetaBool True + | s == "false" = MetaBool False + | s == "False" = MetaBool False + | s == "FALSE" = MetaBool False + | otherwise = MetaString s -- Transformations of a Pandoc document post-parsing: diff --git a/test/command/5177.md b/test/command/5177.md new file mode 100644 index 000000000..d832780ea --- /dev/null +++ b/test/command/5177.md @@ -0,0 +1,12 @@ +This should not give a "Prelude.read: no parse" error: + +``` +% pandoc -M foo=1e -s -t markdown +hi +^D +--- +foo: 1e +--- + +hi +``` |