prosemirror-highlight 0.11.1 → 0.12.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 +19 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -2
- package/dist/lowlight.d.ts +1 -1
- package/dist/refractor.d.ts +1 -1
- package/dist/shiki.d.ts +1 -1
- package/dist/shiki.js +7 -2
- package/dist/sugar-high.d.ts +1 -1
- package/dist/{types-CwiCqY6X.d.ts → types-BIUZQh-P.d.ts} +4 -0
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -77,6 +77,25 @@ export const shikiLazyPlugin = createHighlightPlugin({ parser: lazyParser })
|
|
|
77
77
|
|
|
78
78
|
</details>
|
|
79
79
|
|
|
80
|
+
<details>
|
|
81
|
+
<summary>Set code block background color based on theme</summary>
|
|
82
|
+
|
|
83
|
+
When using Shiki, two CSS variables are set automatically to the `<pre>` element:
|
|
84
|
+
|
|
85
|
+
- `--prosekit-highlight`: The text color of the code block
|
|
86
|
+
- `--prosekit-highlight-bg`: The background color of the code block
|
|
87
|
+
|
|
88
|
+
You can use these variables to set the background color and text color of the code block.
|
|
89
|
+
|
|
90
|
+
```css
|
|
91
|
+
.ProseMirror pre {
|
|
92
|
+
color: var(--prosekit-highlight, inherit);
|
|
93
|
+
background-color: var(--prosekit-highlight-bg, inherit);
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
</details>
|
|
98
|
+
|
|
80
99
|
### With [lowlight] (based on [Highlight.js])
|
|
81
100
|
|
|
82
101
|
<details>
|
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-BIUZQh-P.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Represents a cache of doc positions to the node and decorations at that position
|
package/dist/index.js
CHANGED
|
@@ -79,7 +79,7 @@ function createHighlightPlugin({
|
|
|
79
79
|
nodeTypes = ["code_block", "codeBlock"],
|
|
80
80
|
languageExtractor = (node) => node.attrs.language
|
|
81
81
|
}) {
|
|
82
|
-
const key = new PluginKey();
|
|
82
|
+
const key = new PluginKey("prosemirror-highlight");
|
|
83
83
|
return new Plugin({
|
|
84
84
|
key,
|
|
85
85
|
state: {
|
|
@@ -166,7 +166,8 @@ function calculateDecoration(doc, parser, nodeTypes, languageExtractor, cache) {
|
|
|
166
166
|
const decorations = parser({
|
|
167
167
|
content: node.textContent,
|
|
168
168
|
language: language || void 0,
|
|
169
|
-
pos
|
|
169
|
+
pos,
|
|
170
|
+
size: node.nodeSize
|
|
170
171
|
});
|
|
171
172
|
if (decorations && Array.isArray(decorations)) {
|
|
172
173
|
cache.set(pos, node, decorations);
|
package/dist/lowlight.d.ts
CHANGED
package/dist/refractor.d.ts
CHANGED
package/dist/shiki.d.ts
CHANGED
package/dist/shiki.js
CHANGED
|
@@ -2,16 +2,21 @@
|
|
|
2
2
|
import { Decoration } from "prosemirror-view";
|
|
3
3
|
import "shiki";
|
|
4
4
|
function createParser(highlighter, options) {
|
|
5
|
-
return function parser({ content, language, pos }) {
|
|
5
|
+
return function parser({ content, language, pos, size }) {
|
|
6
6
|
var _a;
|
|
7
7
|
const decorations = [];
|
|
8
|
-
const { tokens } = highlighter.codeToTokens(content, {
|
|
8
|
+
const { tokens, fg, bg, rootStyle } = highlighter.codeToTokens(content, {
|
|
9
9
|
lang: language,
|
|
10
10
|
// Use provided options for themes or just use first loaded theme
|
|
11
11
|
...options != null ? options : {
|
|
12
12
|
theme: highlighter.getLoadedThemes()[0]
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
|
+
const style = rootStyle || (fg && bg ? `--prosekit-highlight:${fg};--prosekit-highlight-bg:${bg}` : "");
|
|
16
|
+
if (style) {
|
|
17
|
+
const decoration = Decoration.node(pos, pos + size, { style });
|
|
18
|
+
decorations.push(decoration);
|
|
19
|
+
}
|
|
15
20
|
let from = pos + 1;
|
|
16
21
|
for (const line of tokens) {
|
|
17
22
|
for (const token of line) {
|
package/dist/sugar-high.d.ts
CHANGED
|
@@ -20,6 +20,10 @@ type Parser = (options: {
|
|
|
20
20
|
* The language of the code block node.
|
|
21
21
|
*/
|
|
22
22
|
language?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The size of the code block node.
|
|
25
|
+
*/
|
|
26
|
+
size: number;
|
|
23
27
|
}) => Decoration[] | Promise<void>;
|
|
24
28
|
/**
|
|
25
29
|
* A function that extracts the language of a code block node.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prosemirror-highlight",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.12.0",
|
|
5
5
|
"description": "A ProseMirror plugin to highlight code blocks",
|
|
6
6
|
"author": "ocavue <ocavue@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -95,27 +95,27 @@
|
|
|
95
95
|
}
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
98
|
-
"@antfu/ni": "^0.23.
|
|
99
|
-
"@ocavue/eslint-config": "^2.
|
|
98
|
+
"@antfu/ni": "^0.23.2",
|
|
99
|
+
"@ocavue/eslint-config": "^2.12.2",
|
|
100
100
|
"@types/hast": "^3.0.4",
|
|
101
101
|
"@types/node": "^20.17.5",
|
|
102
|
-
"eslint": "^9.
|
|
103
|
-
"highlight.js": "^11.
|
|
102
|
+
"eslint": "^9.17.0",
|
|
103
|
+
"highlight.js": "^11.11.1",
|
|
104
104
|
"jsdom": "^25.0.1",
|
|
105
|
-
"lowlight": "^3.
|
|
106
|
-
"prettier": "^3.4.
|
|
105
|
+
"lowlight": "^3.3.0",
|
|
106
|
+
"prettier": "^3.4.2",
|
|
107
107
|
"prosemirror-example-setup": "^1.2.3",
|
|
108
|
-
"prosemirror-model": "^1.24.
|
|
108
|
+
"prosemirror-model": "^1.24.1",
|
|
109
109
|
"prosemirror-schema-basic": "^1.2.3",
|
|
110
110
|
"prosemirror-state": "^1.4.3",
|
|
111
111
|
"prosemirror-transform": "^1.10.2",
|
|
112
|
-
"prosemirror-view": "^1.37.
|
|
112
|
+
"prosemirror-view": "^1.37.2",
|
|
113
113
|
"refractor": "^4.8.1",
|
|
114
|
-
"shiki": "^2.
|
|
114
|
+
"shiki": "^2.1.0",
|
|
115
115
|
"sugar-high": "^0.8.2",
|
|
116
116
|
"tsup": "^8.3.5",
|
|
117
|
-
"typescript": "^5.
|
|
118
|
-
"vite": "^6.0.
|
|
117
|
+
"typescript": "^5.7.2",
|
|
118
|
+
"vite": "^6.0.11",
|
|
119
119
|
"vitest": "^2.1.8"
|
|
120
120
|
},
|
|
121
121
|
"renovate": {
|