Skip to content

Add class to mdast-util-to-hast #40

Discussion options

You must be logged in to vote

Wow, that new code worked too. I'll post the answer here for quick access:

rehype/add-classes.js

// Thanks @wooorm -> https://github.com/micromark/micromark/discussions/40#discussioncomment-141871

const selectAll = require('hast-util-select').selectAll
const classnames = require('hast-util-classnames')

function rehypeClasses(options) {
	return transform

	function transform(tree) {
		let selector
		let index

		for (selector in options) {
			nodes = selectAll(selector, tree)
			index = -1
			while (++index < nodes.length) {
				classnames(nodes[index], options[selector])
			}
		}
	}
}

module.exports = rehypeClasses

next.config.js

const mdx = [
	options.defaultLoaders.babel,
	{
		loader: 

Replies: 2 comments 10 replies

Comment options

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

@wooorm
Comment options

@wooorm
Comment options

@deadcoder0904
Comment options

@wooorm
Comment options

Comment options

You must be logged in to vote
0 replies
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
2 participants