refactor(tiptap-extensions): Do not import the full lowlight library.
BREAKING CHANGE: `CodeBlockHighlight` was importing the full `lowlight` libraries, including _all_ syntax highlightning definitions from `highlight.js`. The new behavior changes the signature of `CodeBlockHighlight` to accept an object with all syntax highlightning definitions. This means that now the user of the library __MUST__ import languages themselves and tiptap will no longer bundle the full `highlight.js` in itself.
This commit is contained in:
@@ -2,7 +2,7 @@ import { Node, Plugin } from 'tiptap'
|
||||
import { Decoration, DecorationSet } from 'prosemirror-view'
|
||||
import { toggleBlockType, setBlockType, textblockTypeInputRule } from 'tiptap-commands'
|
||||
import { findBlockNodes } from 'prosemirror-utils'
|
||||
import low from 'lowlight'
|
||||
import low from 'lowlight/lib/core'
|
||||
|
||||
function getDecorations(doc) {
|
||||
const decorations = []
|
||||
@@ -12,7 +12,7 @@ function getDecorations(doc) {
|
||||
|
||||
const flatten = list => list.reduce(
|
||||
(a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), [],
|
||||
)
|
||||
)
|
||||
|
||||
function parseNodes(nodes, className = []) {
|
||||
return nodes.map(node => {
|
||||
@@ -63,6 +63,24 @@ function getDecorations(doc) {
|
||||
|
||||
export default class CodeBlockHighlightNode extends Node {
|
||||
|
||||
constructor(options = {}) {
|
||||
super(options)
|
||||
try {
|
||||
Object.entries(this.options.languages).forEach(entry => {
|
||||
const [name, mapping] = entry
|
||||
low.registerLanguage(name, mapping)
|
||||
})
|
||||
} catch (err) {
|
||||
throw new Error('Invalid syntax highlight definitions: define at least one highlight.js language mapping')
|
||||
}
|
||||
}
|
||||
|
||||
get defaultOptions() {
|
||||
return {
|
||||
languages: {},
|
||||
}
|
||||
}
|
||||
|
||||
get name() {
|
||||
return 'code_block'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user