@tiptap/extension-code-block-lowlight 2.0.0-beta.20 → 2.0.0-beta.200
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/README.md +1 -1
- package/dist/packages/extension-code-block-lowlight/src/code-block-lowlight.d.ts +2 -1
- package/dist/packages/extension-code-block-lowlight/src/lowlight-plugin.d.ts +3 -2
- package/dist/tiptap-extension-code-block-lowlight.cjs.js +669 -943
- package/dist/tiptap-extension-code-block-lowlight.cjs.js.map +1 -1
- package/dist/tiptap-extension-code-block-lowlight.esm.js +665 -940
- package/dist/tiptap-extension-code-block-lowlight.esm.js.map +1 -1
- package/dist/tiptap-extension-code-block-lowlight.umd.js +673 -947
- package/dist/tiptap-extension-code-block-lowlight.umd.js.map +1 -1
- package/package.json +11 -9
- package/src/code-block-lowlight.ts +10 -5
- package/src/lowlight-plugin.ts +49 -12
- package/CHANGELOG.md +0 -167
- package/LICENSE.md +0 -21
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.200",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -21,15 +21,17 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@tiptap/core": "^2.0.0-beta.
|
|
24
|
+
"@tiptap/core": "^2.0.0-beta.193",
|
|
25
|
+
"@tiptap/extension-code-block": "^2.0.0-beta.193"
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"prosemirror-model": "^1.14.1",
|
|
31
|
-
"prosemirror-state": "^1.3.4",
|
|
32
|
-
"prosemirror-view": "^1.18.4"
|
|
28
|
+
"prosemirror-model": "^1.18.1",
|
|
29
|
+
"prosemirror-state": "^1.4.1",
|
|
30
|
+
"prosemirror-view": "^1.28.2"
|
|
33
31
|
},
|
|
34
|
-
"
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/ueberdosis/tiptap",
|
|
35
|
+
"directory": "packages/extension-code-block-lowlight"
|
|
36
|
+
}
|
|
35
37
|
}
|
|
@@ -1,23 +1,28 @@
|
|
|
1
|
-
import lowlight from 'lowlight/lib/core'
|
|
2
1
|
import CodeBlock, { CodeBlockOptions } from '@tiptap/extension-code-block'
|
|
2
|
+
|
|
3
3
|
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>({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
addOptions() {
|
|
12
|
+
return {
|
|
13
|
+
...this.parent?.(),
|
|
14
|
+
lowlight: {},
|
|
15
|
+
defaultLanguage: null,
|
|
16
|
+
}
|
|
13
17
|
},
|
|
14
18
|
|
|
15
19
|
addProseMirrorPlugins() {
|
|
16
20
|
return [
|
|
17
21
|
...this.parent?.() || [],
|
|
18
22
|
LowlightPlugin({
|
|
19
|
-
name:
|
|
23
|
+
name: this.name,
|
|
20
24
|
lowlight: this.options.lowlight,
|
|
25
|
+
defaultLanguage: this.options.defaultLanguage,
|
|
21
26
|
}),
|
|
22
27
|
]
|
|
23
28
|
},
|
package/src/lowlight-plugin.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { findChildren } from '@tiptap/core'
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
import highlight from 'highlight.js/lib/core'
|
|
4
|
+
import { Node as ProsemirrorNode } from 'prosemirror-model'
|
|
1
5
|
import { Plugin, PluginKey } from 'prosemirror-state'
|
|
2
6
|
import { Decoration, DecorationSet } from 'prosemirror-view'
|
|
3
|
-
import { Node as ProsemirrorNode } from 'prosemirror-model'
|
|
4
|
-
import { findChildren } from '@tiptap/core'
|
|
5
7
|
|
|
6
8
|
function parseNodes(nodes: any[], className: string[] = []): { text: string, classes: string[] }[] {
|
|
7
9
|
return nodes
|
|
@@ -25,17 +27,32 @@ function parseNodes(nodes: any[], className: string[] = []): { text: string, cla
|
|
|
25
27
|
.flat()
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
function
|
|
30
|
+
function getHighlightNodes(result: any) {
|
|
31
|
+
// `.value` for lowlight v1, `.children` for lowlight v2
|
|
32
|
+
return result.value || result.children || []
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function registered(aliasOrLanguage: string) {
|
|
36
|
+
return Boolean(highlight.getLanguage(aliasOrLanguage))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getDecorations({
|
|
40
|
+
doc,
|
|
41
|
+
name,
|
|
42
|
+
lowlight,
|
|
43
|
+
defaultLanguage,
|
|
44
|
+
}: { doc: ProsemirrorNode, name: string, lowlight: any, defaultLanguage: string | null | undefined }) {
|
|
29
45
|
const decorations: Decoration[] = []
|
|
30
46
|
|
|
31
47
|
findChildren(doc, node => node.type.name === name)
|
|
32
48
|
.forEach(block => {
|
|
33
49
|
let from = block.pos + 1
|
|
34
|
-
const
|
|
50
|
+
const language = block.node.attrs.language || defaultLanguage
|
|
35
51
|
const languages = lowlight.listLanguages()
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
52
|
+
|
|
53
|
+
const nodes = language && (languages.includes(language) || registered(language))
|
|
54
|
+
? getHighlightNodes(lowlight.highlight(language, block.node.textContent))
|
|
55
|
+
: getHighlightNodes(lowlight.highlightAuto(block.node.textContent))
|
|
39
56
|
|
|
40
57
|
parseNodes(nodes).forEach(node => {
|
|
41
58
|
const to = from + node.text.length
|
|
@@ -55,12 +72,25 @@ function getDecorations({ doc, name, lowlight }: { doc: ProsemirrorNode, name: s
|
|
|
55
72
|
return DecorationSet.create(doc, decorations)
|
|
56
73
|
}
|
|
57
74
|
|
|
58
|
-
|
|
59
|
-
return
|
|
75
|
+
function isFunction(param: Function) {
|
|
76
|
+
return typeof param === 'function'
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function LowlightPlugin({ name, lowlight, defaultLanguage }: { name: string, lowlight: any, defaultLanguage: string | null | undefined }) {
|
|
80
|
+
if (!['highlight', 'highlightAuto', 'listLanguages'].every(api => isFunction(lowlight[api]))) {
|
|
81
|
+
throw Error('You should provide an instance of lowlight to use the code-block-lowlight extension')
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const lowlightPlugin: Plugin<any> = new Plugin({
|
|
60
85
|
key: new PluginKey('lowlight'),
|
|
61
86
|
|
|
62
87
|
state: {
|
|
63
|
-
init: (_, { doc }) => getDecorations({
|
|
88
|
+
init: (_, { doc }) => getDecorations({
|
|
89
|
+
doc,
|
|
90
|
+
name,
|
|
91
|
+
lowlight,
|
|
92
|
+
defaultLanguage,
|
|
93
|
+
}),
|
|
64
94
|
apply: (transaction, decorationSet, oldState, newState) => {
|
|
65
95
|
const oldNodeName = oldState.selection.$head.parent.type.name
|
|
66
96
|
const newNodeName = newState.selection.$head.parent.type.name
|
|
@@ -92,7 +122,12 @@ export function LowlightPlugin({ name, lowlight }: { name: string, lowlight: any
|
|
|
92
122
|
})
|
|
93
123
|
)
|
|
94
124
|
) {
|
|
95
|
-
return getDecorations({
|
|
125
|
+
return getDecorations({
|
|
126
|
+
doc: transaction.doc,
|
|
127
|
+
name,
|
|
128
|
+
lowlight,
|
|
129
|
+
defaultLanguage,
|
|
130
|
+
})
|
|
96
131
|
}
|
|
97
132
|
|
|
98
133
|
return decorationSet.map(transaction.mapping, transaction.doc)
|
|
@@ -101,8 +136,10 @@ export function LowlightPlugin({ name, lowlight }: { name: string, lowlight: any
|
|
|
101
136
|
|
|
102
137
|
props: {
|
|
103
138
|
decorations(state) {
|
|
104
|
-
return
|
|
139
|
+
return lowlightPlugin.getState(state)
|
|
105
140
|
},
|
|
106
141
|
},
|
|
107
142
|
})
|
|
143
|
+
|
|
144
|
+
return lowlightPlugin
|
|
108
145
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
# [2.0.0-beta.20](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-code-block-lowlight@2.0.0-beta.19...@tiptap/extension-code-block-lowlight@2.0.0-beta.20) (2021-05-13)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @tiptap/extension-code-block-lowlight
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# [2.0.0-beta.19](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-code-block-lowlight@2.0.0-beta.18...@tiptap/extension-code-block-lowlight@2.0.0-beta.19) (2021-05-13)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package @tiptap/extension-code-block-lowlight
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# [2.0.0-beta.18](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-code-block-lowlight@2.0.0-beta.17...@tiptap/extension-code-block-lowlight@2.0.0-beta.18) (2021-05-07)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
### Bug Fixes
|
|
26
|
-
|
|
27
|
-
* revert adding exports ([bc320d0](https://github.com/ueberdosis/tiptap/commit/bc320d0b4b80b0e37a7e47a56e0f6daec6e65d98))
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
# [2.0.0-beta.17](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-code-block-lowlight@2.0.0-beta.16...@tiptap/extension-code-block-lowlight@2.0.0-beta.17) (2021-05-06)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
### Bug Fixes
|
|
37
|
-
|
|
38
|
-
* revert adding type: module ([f8d6475](https://github.com/ueberdosis/tiptap/commit/f8d6475e2151faea6f96baecdd6bd75880d50d2c))
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
# [2.0.0-beta.16](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-code-block-lowlight@2.0.0-beta.15...@tiptap/extension-code-block-lowlight@2.0.0-beta.16) (2021-05-06)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
### Bug Fixes
|
|
48
|
-
|
|
49
|
-
* add exports to package.json ([1277fa4](https://github.com/ueberdosis/tiptap/commit/1277fa47151e9c039508cdb219bdd0ffe647f4ee))
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
# [2.0.0-beta.15](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-code-block-lowlight@2.0.0-beta.14...@tiptap/extension-code-block-lowlight@2.0.0-beta.15) (2021-05-06)
|
|
56
|
-
|
|
57
|
-
**Note:** Version bump only for package @tiptap/extension-code-block-lowlight
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
# [2.0.0-beta.14](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-code-block-lowlight@2.0.0-beta.13...@tiptap/extension-code-block-lowlight@2.0.0-beta.14) (2021-05-05)
|
|
64
|
-
|
|
65
|
-
**Note:** Version bump only for package @tiptap/extension-code-block-lowlight
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
# [2.0.0-beta.13](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-code-block-lowlight@2.0.0-beta.12...@tiptap/extension-code-block-lowlight@2.0.0-beta.13) (2021-05-04)
|
|
72
|
-
|
|
73
|
-
**Note:** Version bump only for package @tiptap/extension-code-block-lowlight
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
# [2.0.0-beta.12](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-code-block-lowlight@2.0.0-beta.11...@tiptap/extension-code-block-lowlight@2.0.0-beta.12) (2021-04-27)
|
|
80
|
-
|
|
81
|
-
**Note:** Version bump only for package @tiptap/extension-code-block-lowlight
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
# [2.0.0-beta.11](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-code-block-lowlight@2.0.0-beta.10...@tiptap/extension-code-block-lowlight@2.0.0-beta.11) (2021-04-23)
|
|
88
|
-
|
|
89
|
-
**Note:** Version bump only for package @tiptap/extension-code-block-lowlight
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
# [2.0.0-beta.10](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-code-block-lowlight@2.0.0-beta.9...@tiptap/extension-code-block-lowlight@2.0.0-beta.10) (2021-04-22)
|
|
96
|
-
|
|
97
|
-
**Note:** Version bump only for package @tiptap/extension-code-block-lowlight
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
# [2.0.0-beta.9](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-code-block-lowlight@2.0.0-beta.8...@tiptap/extension-code-block-lowlight@2.0.0-beta.9) (2021-04-21)
|
|
104
|
-
|
|
105
|
-
**Note:** Version bump only for package @tiptap/extension-code-block-lowlight
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
# [2.0.0-beta.8](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-code-block-lowlight@2.0.0-beta.7...@tiptap/extension-code-block-lowlight@2.0.0-beta.8) (2021-04-16)
|
|
112
|
-
|
|
113
|
-
**Note:** Version bump only for package @tiptap/extension-code-block-lowlight
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
# [2.0.0-beta.7](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-code-block-lowlight@2.0.0-beta.6...@tiptap/extension-code-block-lowlight@2.0.0-beta.7) (2021-04-15)
|
|
120
|
-
|
|
121
|
-
**Note:** Version bump only for package @tiptap/extension-code-block-lowlight
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
# [2.0.0-beta.6](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-code-block-lowlight@2.0.0-beta.4...@tiptap/extension-code-block-lowlight@2.0.0-beta.6) (2021-04-14)
|
|
128
|
-
|
|
129
|
-
**Note:** Version bump only for package @tiptap/extension-code-block-lowlight
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
# [2.0.0-beta.4](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-code-block-lowlight@2.0.0-beta.3...@tiptap/extension-code-block-lowlight@2.0.0-beta.4) (2021-04-14)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
### Bug Fixes
|
|
139
|
-
|
|
140
|
-
* fix lowlight decorations for vue 3 ([daa5dc0](https://github.com/ueberdosis/tiptap/commit/daa5dc0fb1ec2db6889565fc9c091f3dbdbbda6d))
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
# [2.0.0-beta.3](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-code-block-lowlight@2.0.0-beta.2...@tiptap/extension-code-block-lowlight@2.0.0-beta.3) (2021-04-12)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
### Features
|
|
150
|
-
|
|
151
|
-
* add parentConfig to extension context for more extendable extensions, fix [#259](https://github.com/ueberdosis/tiptap/issues/259) ([5e1ec5d](https://github.com/ueberdosis/tiptap/commit/5e1ec5d2a66be164f505d631f97861ab9344ba96))
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
# [2.0.0-beta.2](https://github.com/ueberdosis/tiptap/compare/@tiptap/extension-code-block-lowlight@2.0.0-beta.1...@tiptap/extension-code-block-lowlight@2.0.0-beta.2) (2021-04-11)
|
|
158
|
-
|
|
159
|
-
**Note:** Version bump only for package @tiptap/extension-code-block-lowlight
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
# 2.0.0-beta.1 (2021-04-08)
|
|
166
|
-
|
|
167
|
-
**Note:** Version bump only for package @tiptap/extension-code-block-lowlight
|
package/LICENSE.md
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021, überdosis GbR
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|