mih

markdown-it-highlightjs

Preset to use highlight.js with markdown-it.

Showing:

Popularity

Downloads/wk

4.4K

GitHub Stars

34

Maintenance

Last Commit

5mos ago

Contributors

6

Package

Dependencies

2

Size (min+gzip)

278.8KB

License

Unlicense

Type Definitions

Tree-Shakeable

No?

Categories

Readme

markdown-it-highlightjs npm version

Preset to use highlight.js with markdown-it.

Usage

const md = require('markdown-it')()
  .use(require('markdown-it-highlightjs'), opts)

// All code blocks will be highlighted.

The opts object can contain:

NameTypeDescriptionDefault
autobooleanWhether to automatically detect language if not specified.true
codebooleanWhether to add the hljs class to raw code blocks (not fenced blocks).true
registerobjectRegister other languages which are not included in the standard pack.null
inlinebooleanWhether to highlight inline code.false
hljsobjectProvide the instance of highlight.js to use for highlightingrequire('highlight.js')

Register languages

const md = require('markdown-it')()
  .use(require('markdown-it-highlightjs'), {
    register: {
      cypher: require('highlightjs-cypher')
    }
  })

Inline code highlighting

You can enable inline code highlighting by setting inline to true:

const md = require('markdown-it')()
  .use(require('markdown-it-highlightjs'), { inline: true })

You can specify the language for inline code using Pandoc syntax:

`x=4`{.js}

or Kramdown IAL syntax:

`x=4`{:.js}

If you do not specify a language, then highlight.js will attempt to guess the language if auto is true (which it is by default).

Provide the highlight.js instance

You can specify the hljs option to override the default highlight.js instance with your own:

const hljs = require('highlight.js/lib/core')

hljs.registerLanguage(
  'javascript',
  require('highlight.js/lib/languages/javascript')
)

const md = require('markdown-it')()
  .use(require('markdown-it-highlightjs'), { hljs })

Core plugin

You may import the core markdown-it-highlightjs plugin directly, without any default options. You must specify an instance of highlight.js for the hljs option.

const hljs = require('highlight.js/lib/core')
const md = require('markdown-it')()
  .use(require('markdown-it-highlightjs/core'), { hljs })

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial