Skip to content

How to parse and serialize custom tags #268

Closed Answered by eemeli
miffels asked this question in Q&A
Discussion options

You must be logged in to vote

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.

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:mat…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@miffels
Comment options

@eemeli
Comment options

Answer selected by miffels
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants