git.iko.soy/typeable/pandoc
on master help sign in
Handle Boolean values in `--metadata`.

Note that anything not parseable as a YAML boolean or string is treated as a literal string. Note that you can still get a string value with "yes" or any of the strings interpretable as booleans: -M boolvalue=yes -M stringvalue='"yes"'

commit652f9a88f4e112804dcb5035783235a08aff3aa8 authorJohn MacFarlane <fiddlosopher@gmail.com> dateThu 19 Sep 2013, 20:21 (13 years ago) parent255037a
2 files changed+15−4
pandoc.cabal+2 pandoc.hs+13−4
pandoc.cabal+2
@@ -345,6 +345,8 @@ Executable pandoc
345345 extensible-exceptions >= 0.1 && < 0.2,
346346 highlighting-kate >= 0.5.5 && < 0.6,
347347 aeson >= 0.6 && < 0.7,
348+ text >= 0.11 && < 0.12,
349+ yaml >= 0.8.3 && < 0.9,
348350 containers >= 0.1 && < 0.6,
349351 HTTP >= 4000.0.5 && < 4000.3
350352 Ghc-Options: -rtsopts -with-rtsopts=-K16m -Wall -fno-warn-unused-do-bind
pandoc.hs+13−4
@@ -63,6 +63,9 @@ import Data.Aeson (eitherDecode', encode)
6363import qualified Data.Map as M
6464import System.IO.Error(ioeGetErrorType)
6565import GHC.IO.Exception (IOErrorType(ResourceVanished))
66+import Data.Yaml (decode)
67+import qualified Data.Yaml as Yaml
68+import qualified Data.Text as T
6669
6770copyrightMessage :: String
6871copyrightMessage = "\nCopyright (C) 2006-2013 John MacFarlane\n" ++
@@ -333,7 +336,7 @@ options =
333336 (ReqArg
334337 (\arg opt -> do
335338 let (key,val) = case break (`elem` ":=") arg of
336− (k,_:v) -> (k, MetaString v)
339+ (k,_:v) -> (k, readMetaValue v)
337340 (k,_) -> (k, MetaBool True)
338341 return opt{ optMetadata = addMetadata key val
339342 $ optMetadata opt })
@@ -664,7 +667,7 @@ options =
664667 , Option "" ["bibliography"]
665668 (ReqArg
666669 (\arg opt -> return opt{ optMetadata = addMetadata
667− "bibliography" (MetaString arg)
670+ "bibliography" (readMetaValue arg)
668671 $ optMetadata opt
669672 })
670673 "FILE")
@@ -674,7 +677,7 @@ options =
674677 (ReqArg
675678 (\arg opt ->
676679 return opt{ optMetadata = addMetadata "csl"
677− (MetaString arg)
680+ (readMetaValue arg)
678681 $ optMetadata opt })
679682 "FILE")
680683 ""
@@ -684,7 +687,7 @@ options =
684687 (\arg opt ->
685688 return opt{ optMetadata = addMetadata
686689 "citation-abbreviations"
687− (MetaString arg)
690+ (readMetaValue arg)
688691 $ optMetadata opt })
689692 "FILE")
690693 ""
@@ -793,6 +796,12 @@ addMetadata k v m = case M.lookup k m of
793796 (MetaList (xs ++ [v])) m
794797 Just x -> M.insert k (MetaList [v, x]) m
795798
799+readMetaValue :: String -> MetaValue
800+readMetaValue s = case decode (UTF8.fromString s) of
801+ Just (Yaml.String t) -> MetaString $ T.unpack t
802+ Just (Yaml.Bool b) -> MetaBool b
803+ _ -> MetaString s
804+
796805-- Returns usage message
797806usageMessage :: String -> [OptDescr (Opt -> IO Opt)] -> String
798807usageMessage programName = usageInfo