1.0.0 • Published 2 years ago

markdown-it-class v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

markdown-it-class

Plugin for markdown-it to allow adding classes to HTML tags.

Install

You can install it using yarn or npm

npm install --save-dev markdown-it-class

Usage

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);

Credits

This package is a fork of HiroshiOkada/markdown-it-class with the support for all sorts of HTML tags. The original package has the invalid conditional logic for assigning classes due to which it misses several HTML tags.

Contributions

Feel free to submit pull requests, create issues or spread the word.

License

MIT © Kamran Ahmed