prosemirror-highlight
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -0,3 +1,7 @@ | ||
import { | ||
fillFromRoot | ||
} from "./chunk-ZZGBRRBM.js"; | ||
// src/lowlight.ts | ||
import { Decoration } from "prosemirror-view"; | ||
import "prosemirror-view"; | ||
function createParser(lowlight) { | ||
@@ -12,44 +16,4 @@ return function highlighter({ content, language, pos }) { | ||
} | ||
function fillFromRoot(decorations, node, from) { | ||
for (const child of node.children) { | ||
from = fillFromRootContent(decorations, child, from); | ||
} | ||
} | ||
function fillFromRootContent(decorations, node, from) { | ||
if (node.type === "element") { | ||
const to = from + getElementSize(node); | ||
const { className, ...rest } = node.properties; | ||
decorations.push( | ||
Decoration.inline(from, to, { | ||
class: className ? Array.isArray(className) ? className.join(" ") : String(className) : void 0, | ||
...rest, | ||
nodeName: node.tagName | ||
}) | ||
); | ||
return to; | ||
} else if (node.type === "text") { | ||
return from + node.value.length; | ||
} else { | ||
return from; | ||
} | ||
} | ||
function getElementSize(node) { | ||
let size = 0; | ||
for (const child of node.children) { | ||
size += getElementContentSize(child); | ||
} | ||
return size; | ||
} | ||
function getElementContentSize(node) { | ||
switch (node.type) { | ||
case "element": | ||
return getElementSize(node); | ||
case "text": | ||
return node.value.length; | ||
default: | ||
return 0; | ||
} | ||
} | ||
export { | ||
createParser | ||
}; |
{ | ||
"name": "prosemirror-highlight", | ||
"type": "module", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"packageManager": "pnpm@8.10.0", | ||
@@ -16,3 +16,12 @@ "description": "A ProseMirror plugin to highlight code blocks", | ||
"bugs": "https://github.com/ocavue/prosemirror-highlight/issues", | ||
"keywords": [], | ||
"keywords": [ | ||
"prosemirror", | ||
"editor", | ||
"highlight.js", | ||
"shiki", | ||
"shikiji", | ||
"refractor", | ||
"lowlight", | ||
"prism" | ||
], | ||
"sideEffects": false, | ||
@@ -29,2 +38,5 @@ "main": "./src/index.ts", | ||
}, | ||
"./refractor": { | ||
"default": "./src/refractor.ts" | ||
}, | ||
"./shiki": { | ||
@@ -58,2 +70,3 @@ "default": "./src/shiki.ts" | ||
"prosemirror-view": "^1.32.4", | ||
"refractor": "^4.8.1", | ||
"shiki": "^0.14.6", | ||
@@ -84,2 +97,5 @@ "shikiji": "^0.8.0" | ||
}, | ||
"refractor": { | ||
"optional": true | ||
}, | ||
"shiki": { | ||
@@ -108,2 +124,3 @@ "optional": true | ||
"prosemirror-view": "^1.32.4", | ||
"refractor": "^4.8.1", | ||
"shiki": "^0.14.6", | ||
@@ -129,2 +146,6 @@ "shikiji": "^0.8.0", | ||
}, | ||
"./refractor": { | ||
"types": "./dist/refractor.d.ts", | ||
"default": "./dist/refractor.js" | ||
}, | ||
"./shiki": { | ||
@@ -131,0 +152,0 @@ "types": "./dist/shiki.d.ts", |
@@ -5,3 +5,3 @@ # prosemirror-highlight | ||
Highlight your code blocks in [ProseMirror], with any syntax highlighter you want. | ||
Highlight your code blocks in [ProseMirror], with any syntax highlighter you like! | ||
@@ -59,2 +59,14 @@ ## Usage | ||
### With [refractor] (based on [Prism]) | ||
```ts | ||
import { refractor } from 'refractor' | ||
import { createHighlightPlugin } from 'prosemirror-highlight' | ||
import { createParser } from 'prosemirror-highlight/refractor' | ||
const parser = createParser(refractor) | ||
export const refractorPlugin = createHighlightPlugin({ parser }) | ||
``` | ||
## Online demo | ||
@@ -78,1 +90,3 @@ | ||
[Shikiji]: https://github.com/antfu/shikiji | ||
[refractor]: https://github.com/wooorm/refractor | ||
[Prism]: https://github.com/PrismJS/prism |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
20099
15
412
90
0
10
22