Plugin for markdown-it to allow adding classes to HTML tags.
You can install it using yarn or npm
npm install --save-dev markdown-it-class
All you have to do is register the plugin and pass the tag to class mapping.
const MarkdownIt = require('markdown-it')
const markdownItClass = require('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 which has outdated dependencies and has improper handling for HTML tags because it relies on the undocumented token types which misses out an unknown number of token types. This fork has up-to-date dependencies and supports all the html types by relying on the documented nesting property of tokens.
Feel free to submit pull requests, create issues or spread the word.
MIT © Kamran Ahmed