git.iko.soy/typeable/pandoc
on master help sign in
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.

commitffc2192caffd101666dd6c793631798d7f22878f authorJohn MacFarlane <jgm@berkeley.edu> dateMon 31 Dec 2018, 21:20 (8 years ago) parentc8b79b0
2 files changed+20−7
src/Text/Pandoc/App.hs+8−7 test/command/5177.md+12
src/Text/Pandoc/App.hs+8−7
@@ -55,7 +55,6 @@ import qualified Data.Text.Lazy as TL
5555import qualified Data.Text.Lazy.Encoding as TE
5656import qualified Data.Text.Encoding.Error as TE
5757import qualified Data.Text.Encoding.Error as TSE
58−import qualified Data.YAML as YAML
5958import Network.URI (URI (..), parseURI)
6059import System.Directory (getAppUserDataDirectory)
6160import System.Exit (exitSuccess)
@@ -332,12 +331,14 @@ removeMetaKeys :: [(String,String)] -> Pandoc -> Pandoc
332331removeMetaKeys kvs pdc = foldr (deleteMeta . fst) pdc kvs
333332
334333readMetaValue :: String -> MetaValue
335−readMetaValue s = case YAML.decodeStrict (UTF8.fromString s) of
336− Right [YAML.Scalar (YAML.SStr t)]
337− -> MetaString $ T.unpack t
338− Right [YAML.Scalar (YAML.SBool b)]
339− -> MetaBool b
340− _ -> MetaString s
334+readMetaValue s
335+ | s == "true" = MetaBool True
336+ | s == "True" = MetaBool True
337+ | s == "TRUE" = MetaBool True
338+ | s == "false" = MetaBool False
339+ | s == "False" = MetaBool False
340+ | s == "FALSE" = MetaBool False
341+ | otherwise = MetaString s
341342
342343-- Transformations of a Pandoc document post-parsing:
343344
test/command/5177.mdnew file+12
@@ -0,0 +1,12 @@
1+This should not give a "Prelude.read: no parse" error:
2+
3+```
4+% pandoc -M foo=1e -s -t markdown
5+hi
6+^D
7+---
8+foo: 1e
9+---
10+
11+hi
12+```