Allow specifying string value in metadata using !!literal tag.

This is experimental.  Normally metadata values are interpreted
as markdown, but if the !!literal tag is used they will be interpreted
as plain strings.

We need to consider whether this can still be implemented if
we switch back from HsYAML to yaml for performance reasons.
This commit is contained in:
John MacFarlane 2020-02-17 09:53:36 -08:00
parent 6a01386cd1
commit 3493d6afaa
3 changed files with 23 additions and 5 deletions

View file

@ -3914,7 +3914,8 @@ from the main markdown input document.
Metadata will be taken from the fields of the YAML object and added to any
existing document metadata. Metadata can contain lists and objects (nested
arbitrarily), but all string scalars will be interpreted as Markdown. Fields
arbitrarily), but all string scalars will be interpreted as
Markdown, unless marked with the YAML tag `!!literal`. Fields
with names ending in an underscore will be ignored by pandoc. (They may be
given a role by external processors.) Field names must not be
interpretable as YAML numbers or boolean values (so, for
@ -3945,6 +3946,11 @@ when the field contains blank lines or block-level formatting:
This is the abstract.
It consists of two paragraphs.
# This is a YAML comment; it will be ignored.
# The following field is marked as literal and will be
# interpreted as a literal string rather than Markdown:
catalog_number: !!literal '*abc123<f>*'
...
Template variables will be set automatically from the metadata. Thus, for

View file

@ -99,8 +99,10 @@ yamlToMetaValue pBlocks (YAML.Scalar _ x) =
YAML.SBool b -> return $ return $ MetaBool b
YAML.SFloat d -> return $ return $ MetaString $ tshow d
YAML.SInt i -> return $ return $ MetaString $ tshow i
YAML.SUnknown _ t ->
case checkBoolean t of
YAML.SUnknown tag t
| (T.takeWhileEnd (/= ':') <$> YE.tagToText tag) ==
Just "literal" -> return $ return $ MetaString t
| otherwise -> case checkBoolean t of
Just b -> return $ return $ MetaBool b
Nothing -> toMetaValue pBlocks t
YAML.SNull -> return $ return $ MetaString ""

View file

@ -0,0 +1,10 @@
```
% pandoc -t native -s
---
hi: !!literal '*ook*'
there: '*ook*'
...
^D
Pandoc (Meta {unMeta = fromList [("hi",MetaString "*ook*"),("there",MetaInlines [Emph [Str "ook"]])]})
[]
```