Skip to content

Embed mdast AST in Markdown "template"? #54

Answered by ChristianMurphy
jablko asked this question in Q&A
Discussion options

You must be logged in to vote

If not (a way doesn't already exist), I guess how I'd approach it is with some kind of micromark extension? Maybe micromark-extension-directive? Interleave the template strings with the extension, parse, then walk the result and swap the extension nodes for the template args?

In theory, yes.
directives could be inserted as placeholders and replaced by a transformer.

Is there a better way?

Potentially yes.
One approach would be to use MDX, which could look like:

import Mdx from "@mdx-js/runtime";

const mainDocument = `- <Emphasis />`;
const childEmphasisDcoument = `*emphasis*`;

export default function App() {
  return (
    <Mdx
      components={{
        Emphasis: () => <Mdx>{child…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jablko
Comment options

Answer selected by ChristianMurphy
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