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

commit3493d6afaa6586c46898cf8bdb0c45bb70d31f28 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 17 Feb 2020, 09:53 (7 years ago) parent6a01386
3 files changed+23−5
MANUAL.txt+7−1 src/Text/Pandoc/Readers/Metadata.hs+6−4 test/command/literal-tag.md+10
MANUAL.txt+7−1
@@ -3914,7 +3914,8 @@ from the main markdown input document.
39143914
39153915Metadata will be taken from the fields of the YAML object and added to any
39163916existing document metadata. Metadata can contain lists and objects (nested
3917−arbitrarily), but all string scalars will be interpreted as Markdown. Fields
3917+arbitrarily), but all string scalars will be interpreted as
3918+Markdown, unless marked with the YAML tag `!!literal`. Fields
39183919with names ending in an underscore will be ignored by pandoc. (They may be
39193920given a role by external processors.) Field names must not be
39203921interpretable as YAML numbers or boolean values (so, for
@@ -3945,6 +3946,11 @@ when the field contains blank lines or block-level formatting:
39453946 This is the abstract.
39463947
39473948 It consists of two paragraphs.
3949+
3950+ # This is a YAML comment; it will be ignored.
3951+ # The following field is marked as literal and will be
3952+ # interpreted as a literal string rather than Markdown:
3953+ catalog_number: !!literal '*abc123<f>*'
39483954 ...
39493955
39503956Template variables will be set automatically from the metadata. Thus, for
src/Text/Pandoc/Readers/Metadata.hs+6−4
@@ -99,10 +99,12 @@ yamlToMetaValue pBlocks (YAML.Scalar _ x) =
9999 YAML.SBool b -> return $ return $ MetaBool b
100100 YAML.SFloat d -> return $ return $ MetaString $ tshow d
101101 YAML.SInt i -> return $ return $ MetaString $ tshow i
102− YAML.SUnknown _ t ->
103− case checkBoolean t of
104− Just b -> return $ return $ MetaBool b
105− Nothing -> toMetaValue pBlocks t
102+ YAML.SUnknown tag t
103+ | (T.takeWhileEnd (/= ':') <$> YE.tagToText tag) ==
104+ Just "literal" -> return $ return $ MetaString t
105+ | otherwise -> case checkBoolean t of
106+ Just b -> return $ return $ MetaBool b
107+ Nothing -> toMetaValue pBlocks t
106108 YAML.SNull -> return $ return $ MetaString ""
107109
108110yamlToMetaValue pBlocks (YAML.Sequence _ _ xs) = do
test/command/literal-tag.mdnew file+10
@@ -0,0 +1,10 @@
1+```
2+% pandoc -t native -s
3+---
4+hi: !!literal '*ook*'
5+there: '*ook*'
6+...
7+^D
8+Pandoc (Meta {unMeta = fromList [("hi",MetaString "*ook*"),("there",MetaInlines [Emph [Str "ook"]])]})
9+[]
10+```