pandoc/test/command/yaml-metadata-blocks.md
John MacFarlane d226a35c0a Switch back from HsYAML to yaml.
Reasons:

- Performance: HsYAML is around 20 times slower in parsing
  large YAML bibliographies (#6084).
- An issue was submitted to HsYAML, but it hasn't gotten
  any attention.  HsYAML seems borderline unmaintained; it hasn't
  had a commit in over a year.
- Unfortunately this goes back on our attempts to free ourselves
  from C dependencies (#4535).  But I don't see a better alternative
  until a better pure Haskell parser is available.

Closes #6084.

Notes:

- We've removed the FromYAML instances for all types that had
  them, since this is a HsYAML-specific typeclass [API change].
  (The yaml package just uses From/ToJSON.)
- Unlike HsYAML (in the configuration we were using), yaml
  parses 'Y', 'N', 'Yes', 'No', 'On', 'Off' as boolean values.
  Users may need to quote these when they are meant to be
  interpreted as strings.  Similarly, 'null' is parsed as
  a YAML null value (and will be treated as an empty string
  by pandoc rather than the string 'null').  Quoting it will
  force it to be interpreted as a string.
- Some tests had to be adjusted accordingly.
- Pandoc now behaves better when the YAML metadata contains
  escaping errors: instead of just falling back on treating
  the section as a table, it raises a YAML parsing error.
2021-10-27 12:50:51 -07:00

121 lines
2.5 KiB
Markdown

```
% pandoc -s -t native
---
foobar_: this should be ignored
foo:
bar_: as should this
---
^D
Pandoc
Meta
{ unMeta = fromList [ ( "foo" , MetaMap (fromList []) ) ] }
[]
```
```
% pandoc -s -t native
---
# For precedence, see multiple-metadata-blocks.md and vars-and-metadata.md
# For Bools, see also 4819.md
# For Multiline strings, see yaml-with-chomp.md
int: 7
float: 1.5
scientific: 3.7e-5
bool: true
more: False
nothing: null
empty: []
nested:
int: 8
float: 2.5
bool: true
more: False
nothing: null
empty: []
scientific: 3.7e-5
---
^D
Pandoc
Meta
{ unMeta =
fromList
[ ( "bool" , MetaBool True )
, ( "empty" , MetaList [] )
, ( "float" , MetaInlines [ Str "1.5" ] )
, ( "int" , MetaInlines [ Str "7" ] )
, ( "more" , MetaBool False )
, ( "nested"
, MetaMap
(fromList
[ ( "bool" , MetaBool True )
, ( "empty" , MetaList [] )
, ( "float" , MetaInlines [ Str "2.5" ] )
, ( "int" , MetaInlines [ Str "8" ] )
, ( "more" , MetaBool False )
, ( "nothing" , MetaString "" )
, ( "scientific" , MetaInlines [ Str "3.7e-5" ] )
])
)
, ( "nothing" , MetaString "" )
, ( "scientific" , MetaInlines [ Str "3.7e-5" ] )
]
}
[]
```
```
% pandoc -s -t native
---
array:
- foo: bar
- bool: True
---
^D
Pandoc
Meta
{ unMeta =
fromList
[ ( "array"
, MetaList
[ MetaMap
(fromList [ ( "foo" , MetaInlines [ Str "bar" ] ) ])
, MetaMap (fromList [ ( "bool" , MetaBool True ) ])
]
)
]
}
[]
```
```
% pandoc -s -t native --metadata-file command/yaml-metadata.yaml
---
title: document
---
^D
Pandoc
Meta
{ unMeta =
fromList
[ ( "other"
, MetaInlines
[ Emph [ Str "markdown" ] , Space , Str "value" ]
)
, ( "title" , MetaInlines [ Str "document" ] )
]
}
[]
```
```
% pandoc -s -t native --metadata-file command/yaml-metadata.yaml -M title=cmdline
^D
Pandoc
Meta
{ unMeta =
fromList
[ ( "other"
, MetaInlines
[ Emph [ Str "markdown" ] , Space , Str "value" ]
)
, ( "title" , MetaString "cmdline" )
]
}
[]
```