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.
This commit is contained in:
parent
030e8969c7
commit
b76203ccf1
2 changed files with 62 additions and 1 deletions
|
@ -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
|
||||
|
|
50
test/command/4819.md
Normal file
50
test/command/4819.md
Normal file
|
@ -0,0 +1,50 @@
|
|||
```
|
||||
% pandoc -f markdown -t native -s
|
||||
---
|
||||
foo: 42
|
||||
...
|
||||
^D
|
||||
Pandoc (Meta {unMeta = fromList [("foo",MetaInlines [Str "42"])]})
|
||||
[]
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc -f markdown -t native -s
|
||||
---
|
||||
foo: true
|
||||
...
|
||||
^D
|
||||
Pandoc (Meta {unMeta = fromList [("foo",MetaBool True)]})
|
||||
[]
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc -f markdown -t native -s
|
||||
---
|
||||
foo: True
|
||||
...
|
||||
^D
|
||||
Pandoc (Meta {unMeta = fromList [("foo",MetaBool True)]})
|
||||
[]
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc -f markdown -t native -s
|
||||
---
|
||||
foo: FALSE
|
||||
...
|
||||
^D
|
||||
Pandoc (Meta {unMeta = fromList [("foo",MetaBool False)]})
|
||||
[]
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc -f markdown -t native -s
|
||||
---
|
||||
foo: no
|
||||
...
|
||||
^D
|
||||
Pandoc (Meta {unMeta = fromList [("foo",MetaInlines [Str "no"])]})
|
||||
[]
|
||||
```
|
||||
|
Loading…
Add table
Reference in a new issue