aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-08-07 09:26:11 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2018-08-07 09:26:58 -0700
commitb76203ccf11c44dcea3837d1e06c8a2969be52bc (patch)
tree357a59479024179d251af7355cc5955df2ddca79 /src/Text
parent030e8969c766446f498a478c142c200946b63089 (diff)
downloadpandoc-b76203ccf11c44dcea3837d1e06c8a2969be52bc.tar.gz
Markdown reader: Properly handle boolean values in YAML metadata.
This fixes a regression in 2.2.3, which cause boolean values to be parsed as MetaInlines instead of MetaBool. Note also an undocumented (but desirable) change in 2.2.3: numbers are now parsed as MetaInlines rather than MetaString. Closes #4819.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 3965392d6..c4e8a6524 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -301,6 +301,14 @@ toMetaValue x =
-- not end in a newline, but a "block" set off with
-- `|` or `>` will.
+checkBoolean :: Text -> Maybe Bool
+checkBoolean t =
+ if t == T.pack "true" || t == T.pack "True" || t == T.pack "TRUE"
+ then Just True
+ else if t == T.pack "false" || t == T.pack "False" || t == T.pack "FALSE"
+ then Just False
+ else Nothing
+
yamlToMeta :: PandocMonad m
=> YAML.Node -> MarkdownParser m (F MetaValue)
yamlToMeta (YAML.Scalar x) =
@@ -309,7 +317,10 @@ yamlToMeta (YAML.Scalar x) =
YAML.SBool b -> return $ return $ MetaBool b
YAML.SFloat d -> return $ return $ MetaString (show d)
YAML.SInt i -> return $ return $ MetaString (show i)
- YAML.SUnknown _ t -> toMetaValue t
+ YAML.SUnknown _ t ->
+ case checkBoolean t of
+ Just b -> return $ return $ MetaBool b
+ Nothing -> toMetaValue t
YAML.SNull -> return $ return $ MetaString ""
yamlToMeta (YAML.Sequence _ xs) = do
xs' <- mapM yamlToMeta xs