Custom Components and Plugins Support #587
Replies: 4 comments 2 replies
|
Thanks for the suggestion. Most of the underlying extension points are already available: Custom components and trusted HTML-like tags through VueRendererMarkdown({ components }), setCustomComponents(), and customHtmlTags. Markstream currently uses a markdown-it-ts tokens -> ParsedNode[] pipeline because the custom AST carries streaming and renderer-specific state. Adding rehype directly would introduce a second HAST-based pipeline, so it is probably not the right core abstraction. The remaining gap may be a first-class extension API that: registers custom syntax or markdown-it token types, A renderer-local components prop may also make this easier to discover than app-level or scoped registration. Could you provide one concrete example containing: the input Markdown, That will help determine whether the existing APIs already cover the use case or whether a token-handler/extension registry should be added. |
|
Yes, certainly. I want that: Let us [!!btn!!][Continue][!!btn!!] to chatShould be rendered to: <p>Let us <button className="myBtn">Continue</button> to chat</p>Using a custom function: function customBtn(str: string) {
const match = str.match(/\[!!btn!!\]\[(.+?)\]\[!!btn!!\]/);
if(!match) return str
const text = match[1];
return (<button className="myBtn">{text}</button>)I wish this example approach would help you clearly understand my query. |
|
So, I would have to use a preprocess which converts "[!!btn!!][Continue][!!btn!!]" To <my-custom-btn>Continue</my-custom-btn>Am I right? |
|
Yes — if the exact bracket syntax is required today, preprocess the incoming Markdown before passing it to const normalized = content.replace(
/\[!!btn!!\]\[([^\]]+)\]\[!!btn!!\]/g,
"<my-custom-btn>$1</my-custom-btn>",
)Then opt the tag into the custom-node pipeline and map it to your component: setCustomComponents("chat", {
"my-custom-btn": MyCustomBtn,
})<MarkdownRender
custom-id="chat"
:custom-html-tags="["my-custom-btn"]"
:content="normalized"
/>For LLM output, you can also instruct the model to emit If you need the exact bracket syntax to work incrementally across stream chunks without preprocessing, that is the parser-level inline-rule extension I mentioned; I can turn that into a feature proposal once we have the expected attribute/nesting/error-handling rules. |
Uh oh!
There was an error while loading. Please reload this page.
The Idea
Adding a feature for Custom Components and plugins with custom regexes or matchers would be great.
The implementation
Developers could add support of rehype plugins or something similar.
All reactions