prosemirror-highlight 0.11.0 → 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 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>
@@ -103,7 +122,7 @@ export const lowlightPlugin = createHighlightPlugin({ parser })
103
122
  <summary>Static loading of all languages</summary>
104
123
 
105
124
  ```ts
106
- import { refractor } from 'refractor'
125
+ import { refractor } from 'refractor/lib/all'
107
126
 
108
127
  import { createHighlightPlugin } from 'prosemirror-highlight'
109
128
  import { createParser } from 'prosemirror-highlight/refractor'
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-D9kxOI8-.js';
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);
@@ -1,5 +1,5 @@
1
1
  import { Root } from 'hast';
2
- import { P as Parser } from './types-D9kxOI8-.js';
2
+ import { P as Parser } from './types-BIUZQh-P.js';
3
3
  import 'prosemirror-model';
4
4
  import 'prosemirror-view';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { Refractor } from 'refractor/lib/core';
2
- import { P as Parser } from './types-D9kxOI8-.js';
2
+ import { P as Parser } from './types-BIUZQh-P.js';
3
3
  import 'prosemirror-model';
4
4
  import 'prosemirror-view';
5
5
 
package/dist/shiki.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Highlighter, CodeToTokensOptions, BundledLanguage, BundledTheme } from 'shiki';
2
- import { P as Parser } from './types-D9kxOI8-.js';
2
+ import { P as Parser } from './types-BIUZQh-P.js';
3
3
  import 'prosemirror-model';
4
4
  import 'prosemirror-view';
5
5
 
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) {
@@ -1,4 +1,4 @@
1
- import { P as Parser } from './types-D9kxOI8-.js';
1
+ import { P as Parser } from './types-BIUZQh-P.js';
2
2
  import 'prosemirror-model';
3
3
  import 'prosemirror-view';
4
4
 
@@ -3,8 +3,9 @@ import { Decoration } from 'prosemirror-view';
3
3
 
4
4
  /**
5
5
  * A function that parses the text content of a code block node and returns an
6
- * array of decorations. If the underlying syntax highlighter is still loading,
7
- * you can return a promise that will be resolved when the highlighter is ready.
6
+ * array of ProseMirror decorations. If the underlying syntax highlighter is
7
+ * still loading, you can return a promise that will be resolved when the
8
+ * highlighter is ready.
8
9
  */
9
10
  type Parser = (options: {
10
11
  /**
@@ -19,6 +20,10 @@ type Parser = (options: {
19
20
  * The language of the code block node.
20
21
  */
21
22
  language?: string;
23
+ /**
24
+ * The size of the code block node.
25
+ */
26
+ size: number;
22
27
  }) => Decoration[] | Promise<void>;
23
28
  /**
24
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.11.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",
@@ -59,8 +59,8 @@
59
59
  "prosemirror-transform": "^1.8.0",
60
60
  "prosemirror-view": "^1.32.4",
61
61
  "refractor": "^4.8.1",
62
- "shiki": "^1.9.0",
63
- "sugar-high": "^0.6.1"
62
+ "shiki": "^1.9.0 || ^2.0.0",
63
+ "sugar-high": "^0.6.1 || ^0.7.0 || ^0.8.0"
64
64
  },
65
65
  "peerDependenciesMeta": {
66
66
  "@types/hast": {
@@ -95,27 +95,27 @@
95
95
  }
96
96
  },
97
97
  "devDependencies": {
98
- "@antfu/ni": "^0.23.1",
99
- "@ocavue/eslint-config": "^2.11.1",
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.14.0",
103
- "highlight.js": "^11.10.0",
102
+ "eslint": "^9.17.0",
103
+ "highlight.js": "^11.11.1",
104
104
  "jsdom": "^25.0.1",
105
- "lowlight": "^3.2.0",
106
- "prettier": "^3.4.1",
105
+ "lowlight": "^3.3.0",
106
+ "prettier": "^3.4.2",
107
107
  "prosemirror-example-setup": "^1.2.3",
108
- "prosemirror-model": "^1.24.0",
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.0",
112
+ "prosemirror-view": "^1.37.2",
113
113
  "refractor": "^4.8.1",
114
- "shiki": "^1.24.0",
115
- "sugar-high": "^0.7.5",
114
+ "shiki": "^2.1.0",
115
+ "sugar-high": "^0.8.2",
116
116
  "tsup": "^8.3.5",
117
- "typescript": "^5.6.3",
118
- "vite": "^5.4.11",
117
+ "typescript": "^5.7.2",
118
+ "vite": "^6.0.11",
119
119
  "vitest": "^2.1.8"
120
120
  },
121
121
  "renovate": {