-
Hey, I have a situation where I am transforming a YAML document that has some custom tags in it. I would like to preserve the tags, but I haven't found a way to write them out the same way I received them. So in essence, the flow is YAML document: markdown_extensions:
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg If I fail to supply any markdown_extensions:
- pymdownx.emoji:
emoji_index: ""
emoji_generator: "" I tried to supply custom types like so const twemojiType = {
identify: () => false,
tag: 'tag:yaml.org,2002:python/name:materialx.emoji.twemoji',
resolve: () => '!!python/name:materialx.emoji.twemoji',
stringify: () => '!!python/name:materialx.emoji.twemoji',
};
const toSvgType = {
identify: () => false,
tag: 'tag:yaml.org,2002:python/name:materialx.emoji.to_svg',
resolve: () => '!!python/name:materialx.emoji.to_svg',
stringify: () => '!!python/name:materialx.emoji.to_svg',
};
const yamlOpts = {
customTags: [
twemojiType,
toSvgType,
],
};
const config = YAML.parse(yamlString, yamlOpts);
// ...
YAML.stringify(config); But then the tag is just rendered as a string: markdown_extensions:
- pymdownx.emoji:
emoji_index: "!!python/name:materialx.emoji.twemoji"
emoji_generator: "!!python/name:materialx.emoji.to_svg" Any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Have you tried working with the Document interface that const src = `
markdown_extensions:
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
`
const doc = YAML.parseDocument(src)
doc.getIn(['markdown_extensions', 0, 'pymdownx.emoji', 'emoji_index'], true)
> Scalar {
value: '',
range: [ 97, 97, 97 ],
source: '',
type: 'PLAIN',
tag: 'tag:yaml.org,2002:python/name:materialx.emoji.twemoji'
}
doc.toString()
> 'markdown_extensions:\n' +
' - pymdownx.emoji:\n' +
' emoji_index: !!python/name:materialx.emoji.twemoji ""\n' +
' emoji_generator: !!python/name:materialx.emoji.to_svg ""\n' That's using |
Beta Was this translation helpful? Give feedback.
Have you tried working with the Document interface that
yaml
provides? That's kind of designed for the sort of use case you appear to have.