4.0.1 • Published 2 years ago

markdown-it-highlightjs v4.0.1

Weekly downloads
2,831
License
Unlicense
Repository
github
Last release
2 years ago

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')
ignoreIllegalsbooleanForces highlighting to finish even in case of detecting illegal syntax for the language instead of throwing an exception.true

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

Usage with markdown-it-attrs

If you use markdown-it-attrs, make sure to include it after markdown-it-highlightjs if you want inline code highlighting to work:

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

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 })
mypen@theonlyjan/vue-markdown-it@hyiromori/lib-js-markdown@everseenflash/mypen@everseenflash/pen-middleware@logture/corestatic-site-express@everything-registry/sub-chunk-2132grunt-slice-markdownjhedhttp-server-mdjambinokohyperz-utilsvuetify-markdown-editormarkservmarktreemarkdown-it-custom-pluginsmd-fileservermarkdown-diagrammarkdown2html-promarkdown2html-less@aura-group/aura-desigin-proekiras-markdown-itgietergenerate-feedopen-letteroh-hi-markdownpenkibbelingnorska-htmlnuxt-collectionsnever-writemttjpiral-docs-toolspdfify-nodemeta-docmotes-mdprep-barv11pixi-webdoc-templater-pressrddsemantic.jsscholae-dicimusscatparty-web-siteserve-markdown-itreflectjs-corereact-rich-markdowntop-bunuek-react-markdownuek-react-mduncratestater-swigspacejs-utilssmgsimstructtms-mdhtmltrilloswagger-view@pidoc/core@navanjr/vuetify-markdown-editor@mryhryki/markdown@netbeifeng/ilv-interactive-video-authoring-tool@nocobase/client@elucidata/tilt@ekiras/markdown-ityoginth-pen@ryanlee2014/markdown-itvide-plugin-toolbar-markdownvite-plugin-md-to-html@mozilla-frontend-infra/components@motes/md@ginee-dev/ginee-x@hackbg/ensuite@halo-dev/halo-markdown-editorsitedown@pixi/webdoc-templatedocprintvue3-markdown-itdocarysxiteupv3-markdown-editorws-image-manager@jamesperet/codex-server@hcgatewood/appa@jsliushen-fe/v-ui@eugene-larychev/or-ui-components4xx@suehok/vuetify-markdown-editor@suxueweibo/vue3-markdown-it@uther/netiler-ui@webdoc/legacy-template@widebluesky/text-x@widebluesky/vue3-ginee-x@widebluesky/test_xu11ty-nunjucks-md@blocker/steem-parsers@wulechuan/generate-html-via-markdown@bret/siteup@breejs/api
4.0.1

2 years ago

4.0.0

2 years ago

3.6.0

2 years ago

3.5.0

3 years ago

3.4.0

3 years ago

3.3.1

3 years ago

3.3.0

4 years ago

3.2.0

4 years ago

3.1.0

4 years ago

3.0.0

7 years ago

2.0.0

9 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago