Ability to extend the default fence codeblock to include meta options. #318
Replies: 2 comments 3 replies
-
Markdoc has built-in support for adding custom attributes to fences. If you add an annotation to that opening line, it will parse the attributes and expose them on the fence's AST node:
You can use this functionality to customize the behavior of fence nodes and add metadata that is accessible in transform functions. You can also override the schema for a fence node to declare the attributes so that the attribute values are validated. We use this functionality at Stripe to support line highlighting and other specialized behaviors we want in fences. Does that meet your needs? We probably could expose the raw unparsed value of the line if there's really a compelling use case, but I want to encourage people to take advantage of the attribute system instead if possible. |
Beta Was this translation helpful? Give feedback.
-
That totally works for me! I didn't know that codeblocks could be used to add attributes like that! |
Beta Was this translation helpful? Give feedback.
-
So, from the default parsing method extended from markdoc, it reads the "language" tag from the start of the fence to first space.
markdoc/src/parser.ts
Line 52 in dcc4d46
I understand that markdoc aim's to be precisely compliant with markdown, but are there any issues with adding that entire line's information, to a "meta" attribute, which does not need to be rendered by default? That ensures an easy to parse area for attributes to the fences while remaining compatible with markdown, and would allow the fences to be used as a more flexible code-block component, which's what it's meant to do, over adding yet another code tag for any simple function, like highlighting a particular line.
Beta Was this translation helpful? Give feedback.
All reactions