Fork of the Highlight.js Line Numbers plugin for Highlight.js line refactored for ESM.
Copy the src/highlightjs-line-numbers.js
file into your project.
Import both Highlight.js and the highlightjs-line-numbers.js
file, then register the plugin:
// Import both libraries
import hljs from 'highlight.js'
import { registerHljsLineNumbers, injectHljsLineNumbersCss } from './src/highlightjs-line-numbers.js'
// Register the plugin
registerHljsLineNumbers(hljs)
// Optionally inject the default CSS for line numbers
injectHljsLineNumbersCss()
registerHljsLineNumbers(hljs)
requires thehljs
instance to be passed as its sole parameter.injectHljsLineNumbersCss()
will inject the base CSS for this plugin.
You can then call the hljs.lineNumbersBlock()
, hljs.initLineNumbersOnLoad()
and hljs.lineNumbersValue()
methods as needed.
For more info, read the original plugin documentation.