@tiptap/extension-code-block-lowlight 2.0.0-beta.50 → 2.0.0-beta.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/code-block-lowlight.ts +3 -0
- package/src/lowlight-plugin.ts +21 -5
- package/dist/packages/extension-code-block-lowlight/src/code-block-lowlight.d.ts +0 -5
- package/dist/packages/extension-code-block-lowlight/src/index.d.ts +0 -3
- package/dist/packages/extension-code-block-lowlight/src/lowlight-plugin.d.ts +0 -5
- package/dist/tiptap-extension-code-block-lowlight.cjs.js +0 -2995
- package/dist/tiptap-extension-code-block-lowlight.cjs.js.map +0 -1
- package/dist/tiptap-extension-code-block-lowlight.esm.js +0 -2986
- package/dist/tiptap-extension-code-block-lowlight.esm.js.map +0 -1
- package/dist/tiptap-extension-code-block-lowlight.umd.js +0 -2996
- package/dist/tiptap-extension-code-block-lowlight.umd.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/extension-code-block-lowlight",
|
|
3
3
|
"description": "code block extension for tiptap",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.54",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -24,17 +24,17 @@
|
|
|
24
24
|
"@tiptap/core": "^2.0.0-beta.1"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@tiptap/extension-code-block": "^2.0.0-beta.
|
|
27
|
+
"@tiptap/extension-code-block": "^2.0.0-beta.28",
|
|
28
28
|
"@types/lowlight": "^0.0.3",
|
|
29
29
|
"lowlight": "^1.20.0",
|
|
30
30
|
"prosemirror-model": "^1.15.0",
|
|
31
31
|
"prosemirror-state": "^1.3.4",
|
|
32
|
-
"prosemirror-view": "^1.
|
|
32
|
+
"prosemirror-view": "^1.22.0"
|
|
33
33
|
},
|
|
34
34
|
"repository": {
|
|
35
35
|
"type": "git",
|
|
36
36
|
"url": "https://github.com/ueberdosis/tiptap",
|
|
37
37
|
"directory": "packages/extension-code-block-lowlight"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "fce16e805824972834d5a8ce8d60e3ff41d63c7e"
|
|
40
40
|
}
|
|
@@ -4,6 +4,7 @@ import { LowlightPlugin } from './lowlight-plugin'
|
|
|
4
4
|
|
|
5
5
|
export interface CodeBlockLowlightOptions extends CodeBlockOptions {
|
|
6
6
|
lowlight: any,
|
|
7
|
+
defaultLanguage: string | null | undefined,
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export const CodeBlockLowlight = CodeBlock.extend<CodeBlockLowlightOptions>({
|
|
@@ -11,6 +12,7 @@ export const CodeBlockLowlight = CodeBlock.extend<CodeBlockLowlightOptions>({
|
|
|
11
12
|
return {
|
|
12
13
|
...this.parent?.(),
|
|
13
14
|
lowlight,
|
|
15
|
+
defaultLanguage: null,
|
|
14
16
|
}
|
|
15
17
|
},
|
|
16
18
|
|
|
@@ -20,6 +22,7 @@ export const CodeBlockLowlight = CodeBlock.extend<CodeBlockLowlightOptions>({
|
|
|
20
22
|
LowlightPlugin({
|
|
21
23
|
name: this.name,
|
|
22
24
|
lowlight: this.options.lowlight,
|
|
25
|
+
defaultLanguage: this.options.defaultLanguage,
|
|
23
26
|
}),
|
|
24
27
|
]
|
|
25
28
|
},
|
package/src/lowlight-plugin.ts
CHANGED
|
@@ -30,13 +30,19 @@ function getHighlightNodes(result: any) {
|
|
|
30
30
|
return result.value || result.children || []
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
function getDecorations({
|
|
33
|
+
function getDecorations({
|
|
34
|
+
doc,
|
|
35
|
+
name,
|
|
36
|
+
lowlight,
|
|
37
|
+
defaultLanguage,
|
|
38
|
+
}: { doc: ProsemirrorNode, name: string, lowlight: any, defaultLanguage: string | null | undefined }) {
|
|
34
39
|
const decorations: Decoration[] = []
|
|
35
40
|
|
|
36
41
|
findChildren(doc, node => node.type.name === name)
|
|
37
42
|
.forEach(block => {
|
|
38
43
|
let from = block.pos + 1
|
|
39
|
-
const
|
|
44
|
+
const language = block.node.attrs.language || defaultLanguage
|
|
45
|
+
console.log({ language, defaultLanguage })
|
|
40
46
|
const languages = lowlight.listLanguages()
|
|
41
47
|
const nodes = language && languages.includes(language)
|
|
42
48
|
? getHighlightNodes(lowlight.highlight(language, block.node.textContent))
|
|
@@ -60,12 +66,17 @@ function getDecorations({ doc, name, lowlight }: { doc: ProsemirrorNode, name: s
|
|
|
60
66
|
return DecorationSet.create(doc, decorations)
|
|
61
67
|
}
|
|
62
68
|
|
|
63
|
-
export function LowlightPlugin({ name, lowlight }: { name: string, lowlight: any }) {
|
|
69
|
+
export function LowlightPlugin({ name, lowlight, defaultLanguage }: { name: string, lowlight: any, defaultLanguage: string | null | undefined }) {
|
|
64
70
|
return new Plugin({
|
|
65
71
|
key: new PluginKey('lowlight'),
|
|
66
72
|
|
|
67
73
|
state: {
|
|
68
|
-
init: (_, { doc }) => getDecorations({
|
|
74
|
+
init: (_, { doc }) => getDecorations({
|
|
75
|
+
doc,
|
|
76
|
+
name,
|
|
77
|
+
lowlight,
|
|
78
|
+
defaultLanguage,
|
|
79
|
+
}),
|
|
69
80
|
apply: (transaction, decorationSet, oldState, newState) => {
|
|
70
81
|
const oldNodeName = oldState.selection.$head.parent.type.name
|
|
71
82
|
const newNodeName = newState.selection.$head.parent.type.name
|
|
@@ -97,7 +108,12 @@ export function LowlightPlugin({ name, lowlight }: { name: string, lowlight: any
|
|
|
97
108
|
})
|
|
98
109
|
)
|
|
99
110
|
) {
|
|
100
|
-
return getDecorations({
|
|
111
|
+
return getDecorations({
|
|
112
|
+
doc: transaction.doc,
|
|
113
|
+
name,
|
|
114
|
+
lowlight,
|
|
115
|
+
defaultLanguage,
|
|
116
|
+
})
|
|
101
117
|
}
|
|
102
118
|
|
|
103
119
|
return decorationSet.map(transaction.mapping, transaction.doc)
|