We’re using markdown + liquid with custom liquid tags.
This looks so similar to that.
This looks so similar to that.
The key advantage of using Markdoc instead of using Markdown with liquid or another string-based templating system that preprocess the content is that the tags and other custom syntax are a first-class part of the Markdoc format. The document parses to an AST and the individual tags can programmatically manipulate the content and document node hierarchy instead of just manipulating or outputting strings of text that are passed on to a Markdown processor.
Perhaps an example may be useful? Or do you have an example where Markdoc custom tags are especially different/better than Liquid custom tags?
Markdoc custom tag syntax:
{% bold %}
Lorem ipsum
{% /bold %}
Liquid custom tag syntax: {% bold %}
Lorem ipsum
{% endbold %}
Markdoc custom tag code is like this in JavaScript: export const bold = {
render: 'Bold'
…
};
import \* as React from 'react';
function Foo({ children }) {
return (
<b>{children}</b>
);
}
return Markdoc.renderers.react(
content, React, {
components: {
Bold: Bold
}
}
);
Liquid custom tag code is like this in Ruby: class Bold < Liquid::Block
def initialize(_tag_name, _content, parse_context)
super
# Do whatever you want here,
# such as parsing to your favorite AST,
# or calling a DB, or RPC, or API, etc.
end
def render(context)
# Do whatever you want here,
# such as processing your favorite AST,
# or using the rend context vars, etc.
"<b>" + super.strip + "</b>"
end
end
Liquid::Template.register_tag("bold", Bold)
print Liquid::Template.parse(File.read("my.txt")).render