Use custom code
component from MDXComponents
in Remark plugin
#1352
-
I have a const visit = require('unist-util-visit')
const toHast = require('mdast-util-to-hast')
const toHtml = require('hast-util-to-html')
module.exports.list = () => {
return (tree) => {
visit(tree, 'list', (node) => {
const str = []
str.push(`<ul class="">`)
for (let i = 0; i < node.children.length; i++) {
for (let j = 0; j < node.children[i].children.length; j++) {
const k = node.children[i].children[j].children.map((l) => toHtml(toHast(l))).join('')
str.push(`<li class="">${k}</li>`)
}
}
str.push(`</ul>`)
if (node.lang !== null) {
node.type = 'html'
node.value = str.filter(Boolean).join('')
}
})
}
} My
My MDX components file looks like: src/components/mdx/index.tsimport { Code } from '@/components/mdx/Code'
export const MDXComponents = {
inlineCode: Code,
} src/components/mdx/Code.tsximport { HTMLAttributes } from 'react'
export const Code = ({ className = '', ...props }: HTMLAttributes<HTMLElement>) => (
<code
className={`${className} p-1 overflow-x-auto bg-gray-900 text-blue-gray-200 rounded-md text-base`}
{...props}
/>
) I want to use all the How can I use the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
In Again, you are falling for an XY problem. You are asking for what you think is the solution, but I’m looking for the actual question. Why not use what tailwind provides? https://github.com/tailwindlabs/tailwindcss-typography |
Beta Was this translation helpful? Give feedback.
-
I don't think AST & JSX can be mixed so the question is wrong. Went with another approach that duplicates a little bit of code → micromark/micromark#40 (comment) But using Tailwind Typography might be a better solution :) |
Beta Was this translation helpful? Give feedback.
I don't think AST & JSX can be mixed so the question is wrong.
Went with another approach that duplicates a little bit of code → micromark/micromark#40 (comment)
But using Tailwind Typography might be a better solution :)