Skip to content

Style ul>li using MDX Components? #1325

Discussion options

You must be logged in to vote

Yay, I found the solution. Had to use toHtml(toHast(l)). I wished there was mdast-util-to-html directly.

list.js

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.t…

Replies: 4 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@deadcoder0904
Comment options

@wooorm
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@wooorm
Comment options

@deadcoder0904
Comment options

Answer selected by deadcoder0904
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants