prosemirror-highlight 0.6.0 → 0.7.0
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 +13 -95
- package/dist/index.d.ts +1 -1
- package/dist/lowlight.d.ts +1 -1
- package/dist/refractor.d.ts +1 -1
- package/dist/shiki.d.ts +1 -1
- package/dist/sugar-high.d.ts +1 -1
- package/package.json +18 -28
- package/dist/shikiji.d.ts +0 -8
- package/dist/shikiji.js +0 -26
- package/src/index.ts +0 -3
- /package/dist/{types-hA0ujWQ1.d.ts → types-D9kxOI8-.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/prosemirror-highlight)
|
|
4
4
|
|
|
5
|
-
Highlight your code blocks
|
|
5
|
+
Highlight your [ProseMirror] code blocks with any syntax highlighter you like!
|
|
6
6
|
|
|
7
7
|
## Usage
|
|
8
8
|
|
|
@@ -12,12 +12,12 @@ Highlight your code blocks in [ProseMirror], with any syntax highlighter you lik
|
|
|
12
12
|
<summary>Static loading of a fixed set of languages</summary>
|
|
13
13
|
|
|
14
14
|
```ts
|
|
15
|
-
import {
|
|
15
|
+
import { getSingletonHighlighter } from 'shiki'
|
|
16
16
|
|
|
17
17
|
import { createHighlightPlugin } from 'prosemirror-highlight'
|
|
18
18
|
import { createParser } from 'prosemirror-highlight/shiki'
|
|
19
19
|
|
|
20
|
-
const highlighter = await
|
|
20
|
+
const highlighter = await getSingletonHighlighter({
|
|
21
21
|
themes: ['github-light'],
|
|
22
22
|
langs: ['javascript', 'typescript', 'python'],
|
|
23
23
|
})
|
|
@@ -31,15 +31,17 @@ export const shikiPlugin = createHighlightPlugin({ parser })
|
|
|
31
31
|
<summary>Dynamic loading of arbitrary languages</summary>
|
|
32
32
|
|
|
33
33
|
```ts
|
|
34
|
-
import {
|
|
34
|
+
import {
|
|
35
|
+
getSingletonHighlighter,
|
|
36
|
+
type BuiltinLanguage,
|
|
37
|
+
type Highlighter,
|
|
38
|
+
} from 'shiki'
|
|
35
39
|
|
|
36
40
|
import { createHighlightPlugin } from 'prosemirror-highlight'
|
|
37
41
|
import { createParser, type Parser } from 'prosemirror-highlight/shiki'
|
|
38
42
|
|
|
39
|
-
let highlighterPromise: Promise<void> | undefined
|
|
40
43
|
let highlighter: Highlighter | undefined
|
|
41
44
|
let parser: Parser | undefined
|
|
42
|
-
const loadedLanguages = new Set<string>()
|
|
43
45
|
|
|
44
46
|
/**
|
|
45
47
|
* Lazy load highlighter and highlighter languages.
|
|
@@ -49,25 +51,18 @@ const loadedLanguages = new Set<string>()
|
|
|
49
51
|
* Otherwise, it returns an array of decorations.
|
|
50
52
|
*/
|
|
51
53
|
const lazyParser: Parser = (options) => {
|
|
52
|
-
if (!
|
|
53
|
-
|
|
54
|
+
if (!highlighter) {
|
|
55
|
+
return getSingletonHighlighter({
|
|
54
56
|
themes: ['github-light'],
|
|
55
57
|
langs: [],
|
|
56
58
|
}).then((h) => {
|
|
57
59
|
highlighter = h
|
|
58
60
|
})
|
|
59
|
-
return highlighterPromise
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (!highlighter) {
|
|
63
|
-
return highlighterPromise
|
|
64
61
|
}
|
|
65
62
|
|
|
66
|
-
const language = options.language
|
|
67
|
-
if (language && !
|
|
68
|
-
return highlighter.loadLanguage(language
|
|
69
|
-
loadedLanguages.add(language)
|
|
70
|
-
})
|
|
63
|
+
const language = options.language as BuiltinLanguage
|
|
64
|
+
if (language && !highlighter.getLoadedLanguages().includes(language)) {
|
|
65
|
+
return highlighter.loadLanguage(language)
|
|
71
66
|
}
|
|
72
67
|
|
|
73
68
|
if (!parser) {
|
|
@@ -82,82 +77,6 @@ export const shikiLazyPlugin = createHighlightPlugin({ parser: lazyParser })
|
|
|
82
77
|
|
|
83
78
|
</details>
|
|
84
79
|
|
|
85
|
-
### With [Shikiji]
|
|
86
|
-
|
|
87
|
-
<details>
|
|
88
|
-
<summary>Static loading of a fixed set of languages</summary>
|
|
89
|
-
|
|
90
|
-
```ts
|
|
91
|
-
import { getHighlighter } from 'shikiji'
|
|
92
|
-
|
|
93
|
-
import { createHighlightPlugin } from 'prosemirror-highlight'
|
|
94
|
-
import { createParser } from 'prosemirror-highlight/shikiji'
|
|
95
|
-
|
|
96
|
-
const highlighter = await getHighlighter({
|
|
97
|
-
themes: ['vitesse-light'],
|
|
98
|
-
langs: ['javascript', 'typescript', 'python'],
|
|
99
|
-
})
|
|
100
|
-
const parser = createParser(highlighter)
|
|
101
|
-
export const shikijiPlugin = createHighlightPlugin({ parser })
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
</details>
|
|
105
|
-
|
|
106
|
-
<details>
|
|
107
|
-
<summary>Dynamic loading of arbitrary languages</summary>
|
|
108
|
-
|
|
109
|
-
```ts
|
|
110
|
-
import { getHighlighter, type Highlighter, type BuiltinLanguage } from 'shikiji'
|
|
111
|
-
|
|
112
|
-
import { createHighlightPlugin, type Parser } from 'prosemirror-highlight'
|
|
113
|
-
import { createParser } from 'prosemirror-highlight/shikiji'
|
|
114
|
-
|
|
115
|
-
let highlighterPromise: Promise<void> | undefined
|
|
116
|
-
let highlighter: Highlighter | undefined
|
|
117
|
-
let parser: Parser | undefined
|
|
118
|
-
const loadedLanguages = new Set<string>()
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Lazy load highlighter and highlighter languages.
|
|
122
|
-
*
|
|
123
|
-
* When the highlighter or the required language is not loaded, it returns a
|
|
124
|
-
* promise that resolves when the highlighter or the language is loaded.
|
|
125
|
-
* Otherwise, it returns an array of decorations.
|
|
126
|
-
*/
|
|
127
|
-
const lazyParser: Parser = (options) => {
|
|
128
|
-
if (!highlighterPromise) {
|
|
129
|
-
highlighterPromise = getHighlighter({
|
|
130
|
-
themes: ['vitesse-light'],
|
|
131
|
-
langs: [],
|
|
132
|
-
}).then((h) => {
|
|
133
|
-
highlighter = h
|
|
134
|
-
})
|
|
135
|
-
return highlighterPromise
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (!highlighter) {
|
|
139
|
-
return highlighterPromise
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const language = options.language
|
|
143
|
-
if (language && !loadedLanguages.has(language)) {
|
|
144
|
-
return highlighter.loadLanguage(language as BuiltinLanguage).then(() => {
|
|
145
|
-
loadedLanguages.add(language)
|
|
146
|
-
})
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (!parser) {
|
|
150
|
-
parser = createParser(highlighter)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return parser(options)
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export const shikijiLazyPlugin = createHighlightPlugin({ parser: lazyParser })
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
</details>
|
|
160
|
-
|
|
161
80
|
### With [lowlight] (based on [Highlight.js])
|
|
162
81
|
|
|
163
82
|
<details>
|
|
@@ -241,7 +160,6 @@ MIT
|
|
|
241
160
|
[lowlight]: https://github.com/wooorm/lowlight
|
|
242
161
|
[Highlight.js]: https://github.com/highlightjs/highlight.js
|
|
243
162
|
[Shiki]: https://github.com/shikijs/shiki
|
|
244
|
-
[Shikiji]: https://github.com/antfu/shikiji
|
|
245
163
|
[refractor]: https://github.com/wooorm/refractor
|
|
246
164
|
[Prism]: https://github.com/PrismJS/prism
|
|
247
165
|
[Sugar high]: https://github.com/huozhi/sugar-high
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Node } from 'prosemirror-model';
|
|
2
2
|
import { Transaction, Plugin } from 'prosemirror-state';
|
|
3
3
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
4
|
-
import { P as Parser, L as LanguageExtractor } from './types-
|
|
4
|
+
import { P as Parser, L as LanguageExtractor } from './types-D9kxOI8-.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Represents a cache of doc positions to the node and decorations at that position
|
package/dist/lowlight.d.ts
CHANGED
package/dist/refractor.d.ts
CHANGED
package/dist/shiki.d.ts
CHANGED
package/dist/sugar-high.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prosemirror-highlight",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"packageManager": "pnpm@8.13.1",
|
|
4
|
+
"version": "0.7.0",
|
|
6
5
|
"description": "A ProseMirror plugin to highlight code blocks",
|
|
7
6
|
"author": "ocavue <ocavue@gmail.com>",
|
|
8
7
|
"license": "MIT",
|
|
@@ -18,7 +17,6 @@
|
|
|
18
17
|
"editor",
|
|
19
18
|
"highlight.js",
|
|
20
19
|
"shiki",
|
|
21
|
-
"shikiji",
|
|
22
20
|
"refractor",
|
|
23
21
|
"lowlight",
|
|
24
22
|
"prism"
|
|
@@ -44,10 +42,6 @@
|
|
|
44
42
|
"types": "./dist/shiki.d.ts",
|
|
45
43
|
"default": "./dist/shiki.js"
|
|
46
44
|
},
|
|
47
|
-
"./shikiji": {
|
|
48
|
-
"types": "./dist/shikiji.d.ts",
|
|
49
|
-
"default": "./dist/shikiji.js"
|
|
50
|
-
},
|
|
51
45
|
"./sugar-high": {
|
|
52
46
|
"types": "./dist/sugar-high.d.ts",
|
|
53
47
|
"default": "./dist/sugar-high.js"
|
|
@@ -65,8 +59,7 @@
|
|
|
65
59
|
"prosemirror-transform": "^1.8.0",
|
|
66
60
|
"prosemirror-view": "^1.32.4",
|
|
67
61
|
"refractor": "^4.8.1",
|
|
68
|
-
"shiki": "^1.
|
|
69
|
-
"shikiji": "^0.8.0 || ^0.9.0 || ^0.10.0",
|
|
62
|
+
"shiki": "^1.9.0",
|
|
70
63
|
"sugar-high": "^0.6.1"
|
|
71
64
|
},
|
|
72
65
|
"peerDependenciesMeta": {
|
|
@@ -97,37 +90,33 @@
|
|
|
97
90
|
"shiki": {
|
|
98
91
|
"optional": true
|
|
99
92
|
},
|
|
100
|
-
"shikiji": {
|
|
101
|
-
"optional": true
|
|
102
|
-
},
|
|
103
93
|
"sugar-high": {
|
|
104
94
|
"optional": true
|
|
105
95
|
}
|
|
106
96
|
},
|
|
107
97
|
"devDependencies": {
|
|
108
98
|
"@antfu/ni": "^0.21.12",
|
|
109
|
-
"@ocavue/eslint-config": "^1.
|
|
110
|
-
"@types/hast": "^3.0.
|
|
111
|
-
"@types/node": "^20.
|
|
112
|
-
"eslint": "^8.
|
|
99
|
+
"@ocavue/eslint-config": "^1.6.0",
|
|
100
|
+
"@types/hast": "^3.0.4",
|
|
101
|
+
"@types/node": "^20.14.7",
|
|
102
|
+
"eslint": "^8.57.0",
|
|
113
103
|
"highlight.js": "^11.9.0",
|
|
114
|
-
"jsdom": "^24.
|
|
104
|
+
"jsdom": "^24.1.0",
|
|
115
105
|
"lowlight": "^3.1.0",
|
|
116
|
-
"prettier": "^3.
|
|
106
|
+
"prettier": "^3.3.2",
|
|
117
107
|
"prosemirror-example-setup": "^1.2.2",
|
|
118
|
-
"prosemirror-model": "^1.
|
|
108
|
+
"prosemirror-model": "^1.21.1",
|
|
119
109
|
"prosemirror-schema-basic": "^1.2.2",
|
|
120
110
|
"prosemirror-state": "^1.4.3",
|
|
121
|
-
"prosemirror-transform": "^1.
|
|
122
|
-
"prosemirror-view": "^1.
|
|
111
|
+
"prosemirror-transform": "^1.9.0",
|
|
112
|
+
"prosemirror-view": "^1.33.8",
|
|
123
113
|
"refractor": "^4.8.1",
|
|
124
|
-
"shiki": "^1.
|
|
125
|
-
"
|
|
126
|
-
"
|
|
127
|
-
"
|
|
128
|
-
"
|
|
129
|
-
"
|
|
130
|
-
"vitest": "^1.1.1"
|
|
114
|
+
"shiki": "^1.9.0",
|
|
115
|
+
"sugar-high": "^0.7.0",
|
|
116
|
+
"tsup": "^8.1.0",
|
|
117
|
+
"typescript": "^5.5.2",
|
|
118
|
+
"vite": "^5.3.1",
|
|
119
|
+
"vitest": "^1.6.0"
|
|
131
120
|
},
|
|
132
121
|
"renovate": {
|
|
133
122
|
"dependencyDashboard": true,
|
|
@@ -138,6 +127,7 @@
|
|
|
138
127
|
"scripts": {
|
|
139
128
|
"dev": "vite",
|
|
140
129
|
"build": "tsup",
|
|
130
|
+
"build:playground": "vite build",
|
|
141
131
|
"lint": "eslint .",
|
|
142
132
|
"fix": "eslint --fix . && prettier --write .",
|
|
143
133
|
"start": "esno src/index.ts",
|
package/dist/shikiji.d.ts
DELETED
package/dist/shikiji.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// src/shikiji.ts
|
|
2
|
-
import { Decoration } from "prosemirror-view";
|
|
3
|
-
function createParser(highlighter) {
|
|
4
|
-
return function parser({ content, language, pos }) {
|
|
5
|
-
const decorations = [];
|
|
6
|
-
const tokens = highlighter.codeToThemedTokens(content, {
|
|
7
|
-
lang: language
|
|
8
|
-
});
|
|
9
|
-
let from = pos + 1;
|
|
10
|
-
for (const line of tokens) {
|
|
11
|
-
for (const token of line) {
|
|
12
|
-
const to = from + token.content.length;
|
|
13
|
-
const decoration = Decoration.inline(from, to, {
|
|
14
|
-
style: `color: ${token.color}`
|
|
15
|
-
});
|
|
16
|
-
decorations.push(decoration);
|
|
17
|
-
from = to;
|
|
18
|
-
}
|
|
19
|
-
from += 1;
|
|
20
|
-
}
|
|
21
|
-
return decorations;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export {
|
|
25
|
-
createParser
|
|
26
|
-
};
|
package/src/index.ts
DELETED
|
File without changes
|