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"'
This commit is contained in:
parent
255037a091
commit
652f9a88f4
2 changed files with 15 additions and 4 deletions
|
@ -345,6 +345,8 @@ Executable pandoc
|
|||
extensible-exceptions >= 0.1 && < 0.2,
|
||||
highlighting-kate >= 0.5.5 && < 0.6,
|
||||
aeson >= 0.6 && < 0.7,
|
||||
text >= 0.11 && < 0.12,
|
||||
yaml >= 0.8.3 && < 0.9,
|
||||
containers >= 0.1 && < 0.6,
|
||||
HTTP >= 4000.0.5 && < 4000.3
|
||||
Ghc-Options: -rtsopts -with-rtsopts=-K16m -Wall -fno-warn-unused-do-bind
|
||||
|
|
17
pandoc.hs
17
pandoc.hs
|
@ -63,6 +63,9 @@ import Data.Aeson (eitherDecode', encode)
|
|||
import qualified Data.Map as M
|
||||
import System.IO.Error(ioeGetErrorType)
|
||||
import GHC.IO.Exception (IOErrorType(ResourceVanished))
|
||||
import Data.Yaml (decode)
|
||||
import qualified Data.Yaml as Yaml
|
||||
import qualified Data.Text as T
|
||||
|
||||
copyrightMessage :: String
|
||||
copyrightMessage = "\nCopyright (C) 2006-2013 John MacFarlane\n" ++
|
||||
|
@ -333,7 +336,7 @@ options =
|
|||
(ReqArg
|
||||
(\arg opt -> do
|
||||
let (key,val) = case break (`elem` ":=") arg of
|
||||
(k,_:v) -> (k, MetaString v)
|
||||
(k,_:v) -> (k, readMetaValue v)
|
||||
(k,_) -> (k, MetaBool True)
|
||||
return opt{ optMetadata = addMetadata key val
|
||||
$ optMetadata opt })
|
||||
|
@ -664,7 +667,7 @@ options =
|
|||
, Option "" ["bibliography"]
|
||||
(ReqArg
|
||||
(\arg opt -> return opt{ optMetadata = addMetadata
|
||||
"bibliography" (MetaString arg)
|
||||
"bibliography" (readMetaValue arg)
|
||||
$ optMetadata opt
|
||||
})
|
||||
"FILE")
|
||||
|
@ -674,7 +677,7 @@ options =
|
|||
(ReqArg
|
||||
(\arg opt ->
|
||||
return opt{ optMetadata = addMetadata "csl"
|
||||
(MetaString arg)
|
||||
(readMetaValue arg)
|
||||
$ optMetadata opt })
|
||||
"FILE")
|
||||
""
|
||||
|
@ -684,7 +687,7 @@ options =
|
|||
(\arg opt ->
|
||||
return opt{ optMetadata = addMetadata
|
||||
"citation-abbreviations"
|
||||
(MetaString arg)
|
||||
(readMetaValue arg)
|
||||
$ optMetadata opt })
|
||||
"FILE")
|
||||
""
|
||||
|
@ -793,6 +796,12 @@ addMetadata k v m = case M.lookup k m of
|
|||
(MetaList (xs ++ [v])) m
|
||||
Just x -> M.insert k (MetaList [v, x]) m
|
||||
|
||||
readMetaValue :: String -> MetaValue
|
||||
readMetaValue s = case decode (UTF8.fromString s) of
|
||||
Just (Yaml.String t) -> MetaString $ T.unpack t
|
||||
Just (Yaml.Bool b) -> MetaBool b
|
||||
_ -> MetaString s
|
||||
|
||||
-- Returns usage message
|
||||
usageMessage :: String -> [OptDescr (Opt -> IO Opt)] -> String
|
||||
usageMessage programName = usageInfo
|
||||
|
|
Loading…
Reference in a new issue