Plugin for markdown-it to allow adding classes to HTML tags.
You can install it using yarn or npm
npm install --save-dev @bynect/markdown-it-class
All you have to do is register the plugin and pass the tag to class mapping.
You can also change the mappings dinamically since they are stored in MarkdownIt.mapping
const MarkdownIt = require('markdown-it')
const markdownItClass = require('@bynect/markdown-it-class')
// Setup the markdown renderer
const md = MarkdownIt()
// Register the plugin and pass a tag to class mapping
.use(markdownItClass, {
h1: ['text-2xl', 'font-bold', 'mb-3', 'text-blue-700'],
p: ['text-md'],
});
const markdownString = fs.readFileSync('post.md', 'utf-8');
const html = md.render(markdownString);
// HTML with classes assigned to the tags
console.log(html);
This package is a fork of markdown-it-class that stores the class mappings in the MarkdownIt object for easier modifications.
Feel free to submit pull requests, create issues or spread the word.
MIT © bynect