Skip to content

Instantly share code, notes, and snippets.

@segphault
Created July 5, 2022 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save segphault/cf858d6edca3bf89f29c56145c8609c2 to your computer and use it in GitHub Desktop.
Save segphault/cf858d6edca3bf89f29c56145c8609c2 to your computer and use it in GitHub Desktop.
Definition lists in Markdoc
const Markdoc = require('@markdoc/markdoc');
const example = `
{% definition-list %}
{% definition term="this is the term" %}
This is the definition
{% /definition %}
{% definition term="another term" %}
This is another definition
{% /definition %}
{% /definition-list %}
`;
const config = {
tags: {
'definition-list': { render: 'dl' },
definition: {
attributes: {
term: { type: String },
},
transform(node, config) {
var children = node.transformChildren(config);
return [
new Markdoc.Tag('dt', {}, node.attributes.term),
new Markdoc.Tag('dd', {}, children[0].children),
];
},
},
},
};
const ast = Markdoc.parse(example);
const content = Markdoc.transform(ast, config);
const output = Markdoc.renderers.html(content);
console.log(output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment