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

commitb76203ccf11c44dcea3837d1e06c8a2969be52bc authorJohn MacFarlane <jgm@berkeley.edu> dateTue 7 Aug 2018, 09:26 (8 years ago) parent030e896
2 files changed+62−1
src/Text/Pandoc/Readers/Markdown.hs+12−1 test/command/4819.md+50
src/Text/Pandoc/Readers/Markdown.hs+12−1
@@ -301,6 +301,14 @@ toMetaValue x =
301301 -- not end in a newline, but a "block" set off with
302302 -- `|` or `>` will.
303303
304+checkBoolean :: Text -> Maybe Bool
305+checkBoolean t =
306+ if t == T.pack "true" || t == T.pack "True" || t == T.pack "TRUE"
307+ then Just True
308+ else if t == T.pack "false" || t == T.pack "False" || t == T.pack "FALSE"
309+ then Just False
310+ else Nothing
311+
304312yamlToMeta :: PandocMonad m
305313 => YAML.Node -> MarkdownParser m (F MetaValue)
306314yamlToMeta (YAML.Scalar x) =
@@ -309,7 +317,10 @@ yamlToMeta (YAML.Scalar x) =
309317 YAML.SBool b -> return $ return $ MetaBool b
310318 YAML.SFloat d -> return $ return $ MetaString (show d)
311319 YAML.SInt i -> return $ return $ MetaString (show i)
312− YAML.SUnknown _ t -> toMetaValue t
320+ YAML.SUnknown _ t ->
321+ case checkBoolean t of
322+ Just b -> return $ return $ MetaBool b
323+ Nothing -> toMetaValue t
313324 YAML.SNull -> return $ return $ MetaString ""
314325yamlToMeta (YAML.Sequence _ xs) = do
315326 xs' <- mapM yamlToMeta xs
test/command/4819.mdnew file+50
@@ -0,0 +1,50 @@
1+```
2+% pandoc -f markdown -t native -s
3+---
4+foo: 42
5+...
6+^D
7+Pandoc (Meta {unMeta = fromList [("foo",MetaInlines [Str "42"])]})
8+[]
9+```
10+
11+```
12+% pandoc -f markdown -t native -s
13+---
14+foo: true
15+...
16+^D
17+Pandoc (Meta {unMeta = fromList [("foo",MetaBool True)]})
18+[]
19+```
20+
21+```
22+% pandoc -f markdown -t native -s
23+---
24+foo: True
25+...
26+^D
27+Pandoc (Meta {unMeta = fromList [("foo",MetaBool True)]})
28+[]
29+```
30+
31+```
32+% pandoc -f markdown -t native -s
33+---
34+foo: FALSE
35+...
36+^D
37+Pandoc (Meta {unMeta = fromList [("foo",MetaBool False)]})
38+[]
39+```
40+
41+```
42+% pandoc -f markdown -t native -s
43+---
44+foo: no
45+...
46+^D
47+Pandoc (Meta {unMeta = fromList [("foo",MetaInlines [Str "no"])]})
48+[]
49+```
50+