prosemirror-highlight 0.8.0 → 0.11.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/dist/index.d.ts CHANGED
@@ -67,7 +67,7 @@ declare function createHighlightPlugin({ parser, nodeTypes, languageExtractor, }
67
67
  /**
68
68
  * An array containing all the node type name to target for highlighting.
69
69
  *
70
- * @default ['code_block']
70
+ * @default ['code_block', 'codeBlock']
71
71
  */
72
72
  nodeTypes?: string[];
73
73
  /**
package/dist/index.js CHANGED
@@ -1,7 +1,4 @@
1
1
  // src/cache.ts
2
- import "prosemirror-model";
3
- import "prosemirror-state";
4
- import "prosemirror-view";
5
2
  var DecorationCache = class _DecorationCache {
6
3
  constructor(cache) {
7
4
  this.cache = new Map(cache);
@@ -75,12 +72,11 @@ var DecorationCache = class _DecorationCache {
75
72
  };
76
73
 
77
74
  // src/plugin.ts
78
- import "prosemirror-model";
79
75
  import { Plugin, PluginKey } from "prosemirror-state";
80
76
  import { DecorationSet } from "prosemirror-view";
81
77
  function createHighlightPlugin({
82
78
  parser,
83
- nodeTypes = ["code_block"],
79
+ nodeTypes = ["code_block", "codeBlock"],
84
80
  languageExtractor = (node) => node.attrs.language
85
81
  }) {
86
82
  const key = new PluginKey();
package/dist/lowlight.js CHANGED
@@ -3,7 +3,6 @@ import {
3
3
  } from "./chunk-ZZGBRRBM.js";
4
4
 
5
5
  // src/lowlight.ts
6
- import "prosemirror-view";
7
6
  function createParser(lowlight) {
8
7
  return function highlighter({ content, language, pos }) {
9
8
  const root = language ? lowlight.highlight(language, content) : lowlight.highlightAuto(content);
package/dist/refractor.js CHANGED
@@ -3,7 +3,6 @@ import {
3
3
  } from "./chunk-ZZGBRRBM.js";
4
4
 
5
5
  // src/refractor.ts
6
- import "prosemirror-view";
7
6
  function createParser(refractor) {
8
7
  return function highlighter({ content, language, pos }) {
9
8
  const root = refractor.highlight(content, language || "");
package/dist/shiki.d.ts CHANGED
@@ -1,10 +1,8 @@
1
- import { Highlighter, BundledTheme } from 'shiki';
1
+ import { Highlighter, CodeToTokensOptions, BundledLanguage, BundledTheme } from 'shiki';
2
2
  import { P as Parser } from './types-D9kxOI8-.js';
3
3
  import 'prosemirror-model';
4
4
  import 'prosemirror-view';
5
5
 
6
- declare function createParser(highlighter: Highlighter, options?: {
7
- theme?: BundledTheme;
8
- }): Parser;
6
+ declare function createParser(highlighter: Highlighter, options?: CodeToTokensOptions<BundledLanguage, BundledTheme>): Parser;
9
7
 
10
8
  export { Parser, createParser };
package/dist/shiki.js CHANGED
@@ -1,18 +1,27 @@
1
1
  // src/shiki.ts
2
2
  import { Decoration } from "prosemirror-view";
3
+ import "shiki";
3
4
  function createParser(highlighter, options) {
4
5
  return function parser({ content, language, pos }) {
6
+ var _a;
5
7
  const decorations = [];
6
- const tokens = highlighter.codeToTokensBase(content, {
8
+ const { tokens } = highlighter.codeToTokens(content, {
7
9
  lang: language,
8
- theme: options == null ? void 0 : options.theme
10
+ // Use provided options for themes or just use first loaded theme
11
+ ...options != null ? options : {
12
+ theme: highlighter.getLoadedThemes()[0]
13
+ }
9
14
  });
10
15
  let from = pos + 1;
11
16
  for (const line of tokens) {
12
17
  for (const token of line) {
13
18
  const to = from + token.content.length;
14
19
  const decoration = Decoration.inline(from, to, {
15
- style: `color: ${token.color}`
20
+ // When using `options.themes` the `htmlStyle` field will be set, otherwise `color` will be set
21
+ style: stringifyTokenStyle(
22
+ (_a = token.htmlStyle) != null ? _a : `color: ${token.color}`
23
+ ),
24
+ class: "shiki"
16
25
  });
17
26
  decorations.push(decoration);
18
27
  from = to;
@@ -22,6 +31,10 @@ function createParser(highlighter, options) {
22
31
  return decorations;
23
32
  };
24
33
  }
34
+ function stringifyTokenStyle(token) {
35
+ if (typeof token === "string") return token;
36
+ return Object.entries(token).map(([key, value]) => `${key}:${value}`).join(";");
37
+ }
25
38
  export {
26
39
  createParser
27
40
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "prosemirror-highlight",
3
3
  "type": "module",
4
- "version": "0.8.0",
4
+ "version": "0.11.0",
5
5
  "description": "A ProseMirror plugin to highlight code blocks",
6
6
  "author": "ocavue <ocavue@gmail.com>",
7
7
  "license": "MIT",
@@ -95,28 +95,28 @@
95
95
  }
96
96
  },
97
97
  "devDependencies": {
98
- "@antfu/ni": "^0.21.12",
99
- "@ocavue/eslint-config": "^1.6.0",
98
+ "@antfu/ni": "^0.23.1",
99
+ "@ocavue/eslint-config": "^2.11.1",
100
100
  "@types/hast": "^3.0.4",
101
- "@types/node": "^20.14.7",
102
- "eslint": "^8.57.0",
103
- "highlight.js": "^11.9.0",
104
- "jsdom": "^24.1.0",
105
- "lowlight": "^3.1.0",
106
- "prettier": "^3.3.2",
107
- "prosemirror-example-setup": "^1.2.2",
108
- "prosemirror-model": "^1.21.1",
109
- "prosemirror-schema-basic": "^1.2.2",
101
+ "@types/node": "^20.17.5",
102
+ "eslint": "^9.14.0",
103
+ "highlight.js": "^11.10.0",
104
+ "jsdom": "^25.0.1",
105
+ "lowlight": "^3.2.0",
106
+ "prettier": "^3.4.1",
107
+ "prosemirror-example-setup": "^1.2.3",
108
+ "prosemirror-model": "^1.24.0",
109
+ "prosemirror-schema-basic": "^1.2.3",
110
110
  "prosemirror-state": "^1.4.3",
111
- "prosemirror-transform": "^1.9.0",
112
- "prosemirror-view": "^1.33.8",
111
+ "prosemirror-transform": "^1.10.2",
112
+ "prosemirror-view": "^1.37.0",
113
113
  "refractor": "^4.8.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"
114
+ "shiki": "^1.24.0",
115
+ "sugar-high": "^0.7.5",
116
+ "tsup": "^8.3.5",
117
+ "typescript": "^5.6.3",
118
+ "vite": "^5.4.11",
119
+ "vitest": "^2.1.8"
120
120
  },
121
121
  "renovate": {
122
122
  "dependencyDashboard": true,