Skip to content

Commit 8b51bc2

Browse files
authoredMar 14, 2025··
feat: update refractor to v5 (#88)
1 parent 5690b56 commit 8b51bc2

File tree

6 files changed

+25
-40
lines changed

6 files changed

+25
-40
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export const lowlightPlugin = createHighlightPlugin({ parser })
122122
<summary>Static loading of all languages</summary>
123123

124124
```ts
125-
import { refractor } from 'refractor/lib/all'
125+
import { refractor } from 'refractor/all'
126126

127127
import { createHighlightPlugin } from 'prosemirror-highlight'
128128
import { createParser } from 'prosemirror-highlight/refractor'

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"prosemirror-state": "^1.4.3",
6767
"prosemirror-transform": "^1.8.0",
6868
"prosemirror-view": "^1.32.4",
69-
"refractor": "^4.8.1",
69+
"refractor": "^5.0.0",
7070
"sugar-high": "^0.6.1 || ^0.7.0 || ^0.8.0 || ^0.9.0"
7171
},
7272
"peerDependenciesMeta": {
@@ -118,7 +118,7 @@
118118
"prosemirror-state": "^1.4.3",
119119
"prosemirror-transform": "^1.10.2",
120120
"prosemirror-view": "^1.38.0",
121-
"refractor": "^4.8.1",
121+
"refractor": "^5.0.0",
122122
"shiki": "^3.2.1",
123123
"sugar-high": "^0.9.3",
124124
"tsup": "^8.4.0",

‎playground/refractor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { refractor } from 'refractor/lib/all'
1+
import { refractor } from 'refractor/all'
22

33
import { createHighlightPlugin } from 'prosemirror-highlight'
44
import { createParser } from 'prosemirror-highlight/refractor'

‎pnpm-lock.yaml

+17-29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/refractor.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Root } from 'hast'
22
import type { Decoration } from 'prosemirror-view'
3-
import type { Refractor } from 'refractor/lib/core'
3+
import type { Refractor } from 'refractor/core'
44

55
import { fillFromRoot } from './hast'
66
import type { Parser } from './types'
@@ -9,15 +9,12 @@ export type { Parser }
99

1010
export function createParser(refractor: Refractor): Parser {
1111
return function highlighter({ content, language, pos }) {
12-
const root = refractor.highlight(content, language || '')
12+
const root: Root = refractor.highlight(content, language || '')
1313

1414
const decorations: Decoration[] = []
1515
const from = pos + 1
1616

17-
// @ts-expect-error: the return value of `highlight` is not exactly a `hast.Root`
18-
const hastRoot: Root = root
19-
20-
fillFromRoot(decorations, hastRoot, from)
17+
fillFromRoot(decorations, root, from)
2118
return decorations
2219
}
2320
}

‎test/plugin.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('createHighlightPlugin', () => {
5151

5252
it('can highlight code blocks with refractor', async () => {
5353
const { createParser } = await import('../src/refractor')
54-
const { refractor } = await import('refractor/lib/all')
54+
const { refractor } = await import('refractor/all')
5555

5656
const parser = createParser(refractor)
5757
const plugin = createHighlightPlugin({ parser })

0 commit comments

Comments
 (0)
Please sign in to comment.