@archonk/markdown-to-jsx
v7.7.2-fork-1.0.0-beta
Published
Convert markdown to JSX with ease for React and React-like projects. Super lightweight and highly configurable.
Readme
fork from markdown-to-jsx
options.additionalParserRules
Additional rules to be used in parsing markdown.
Inspired by https://github.com/quantizor/markdown-to-jsx/pull/406
type EmojiNode = {
type: 'emoji'
shortcodes: string
}
type AdditionalNode =
| EmojiNode
render(
compiler<AdditionalNode>(':sun_with_face: and :new_moon_with_face:', {
additionalParserRules:{
emoji: {
match: simpleInlineRegex(/^:(\w+):/),
order: Priority.MAX,
parse(capture) {
return {
shortcodes: capture[1]
}
},
render(node, output, state) {
// node-emoji
return get(node.shortcodes)
}
}
}
})
)will render
🌞 and 🌚options.overridesRulesOption
Overwrite one or more options of the default rule. You can find it in the source code
Inspired by innei/Shiro source code
render(
compiler('## Header 2', {
overridesRulesOption:{
[RuleType.heading]:{
render(node, output, state) {
const level = node.level
return createElement(
`h${level}`,
{ id: node.id },
<>
<span>{output(node.children, state)}</span>
<a href={`#${node.id}`}>
#
</a>
</>
)
}
}
}
})
)will render
<h2 id="header-2">
<span>Header 2</span>
<a href="#header-2">#</a>
</h2>MIT
