Socket
Socket
Sign inDemoInstall

markdown-it-highlightjs

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

markdown-it-highlightjs

Preset to use highlight.js with markdown-it.


Version published
Weekly downloads
17K
decreased by-16.73%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 04 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc