@tiptap/extension-code-block-lowlight 2.0.0-beta.50 → 2.0.0-beta.51
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/packages/extension-code-block-lowlight/src/code-block-lowlight.d.ts +1 -0
- package/dist/packages/extension-code-block-lowlight/src/lowlight-plugin.d.ts +2 -1
- package/dist/tiptap-extension-code-block-lowlight.cjs.js +18 -5
- package/dist/tiptap-extension-code-block-lowlight.cjs.js.map +1 -1
- package/dist/tiptap-extension-code-block-lowlight.esm.js +18 -5
- package/dist/tiptap-extension-code-block-lowlight.esm.js.map +1 -1
- package/dist/tiptap-extension-code-block-lowlight.umd.js +18 -5
- package/dist/tiptap-extension-code-block-lowlight.umd.js.map +1 -1
- package/package.json +3 -3
- package/src/code-block-lowlight.ts +3 -0
- package/src/lowlight-plugin.ts +21 -5
|
@@ -2894,12 +2894,13 @@ function getHighlightNodes(result) {
|
|
|
2894
2894
|
// `.value` for lowlight v1, `.children` for lowlight v2
|
|
2895
2895
|
return result.value || result.children || [];
|
|
2896
2896
|
}
|
|
2897
|
-
function getDecorations({ doc, name, lowlight }) {
|
|
2897
|
+
function getDecorations({ doc, name, lowlight, defaultLanguage, }) {
|
|
2898
2898
|
const decorations = [];
|
|
2899
2899
|
findChildren(doc, node => node.type.name === name)
|
|
2900
2900
|
.forEach(block => {
|
|
2901
2901
|
let from = block.pos + 1;
|
|
2902
|
-
const
|
|
2902
|
+
const language = block.node.attrs.language || defaultLanguage;
|
|
2903
|
+
console.log({ language, defaultLanguage });
|
|
2903
2904
|
const languages = lowlight.listLanguages();
|
|
2904
2905
|
const nodes = language && languages.includes(language)
|
|
2905
2906
|
? getHighlightNodes(lowlight.highlight(language, block.node.textContent))
|
|
@@ -2917,11 +2918,16 @@ function getDecorations({ doc, name, lowlight }) {
|
|
|
2917
2918
|
});
|
|
2918
2919
|
return DecorationSet.create(doc, decorations);
|
|
2919
2920
|
}
|
|
2920
|
-
function LowlightPlugin({ name, lowlight }) {
|
|
2921
|
+
function LowlightPlugin({ name, lowlight, defaultLanguage }) {
|
|
2921
2922
|
return new Plugin({
|
|
2922
2923
|
key: new PluginKey('lowlight'),
|
|
2923
2924
|
state: {
|
|
2924
|
-
init: (_, { doc }) => getDecorations({
|
|
2925
|
+
init: (_, { doc }) => getDecorations({
|
|
2926
|
+
doc,
|
|
2927
|
+
name,
|
|
2928
|
+
lowlight,
|
|
2929
|
+
defaultLanguage,
|
|
2930
|
+
}),
|
|
2925
2931
|
apply: (transaction, decorationSet, oldState, newState) => {
|
|
2926
2932
|
const oldNodeName = oldState.selection.$head.parent.type.name;
|
|
2927
2933
|
const newNodeName = newState.selection.$head.parent.type.name;
|
|
@@ -2949,7 +2955,12 @@ function LowlightPlugin({ name, lowlight }) {
|
|
|
2949
2955
|
&& node.pos + node.node.nodeSize <= step.to;
|
|
2950
2956
|
});
|
|
2951
2957
|
}))) {
|
|
2952
|
-
return getDecorations({
|
|
2958
|
+
return getDecorations({
|
|
2959
|
+
doc: transaction.doc,
|
|
2960
|
+
name,
|
|
2961
|
+
lowlight,
|
|
2962
|
+
defaultLanguage,
|
|
2963
|
+
});
|
|
2953
2964
|
}
|
|
2954
2965
|
return decorationSet.map(transaction.mapping, transaction.doc);
|
|
2955
2966
|
},
|
|
@@ -2968,6 +2979,7 @@ const CodeBlockLowlight = CodeBlock.extend({
|
|
|
2968
2979
|
return {
|
|
2969
2980
|
...(_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this),
|
|
2970
2981
|
lowlight: core$1,
|
|
2982
|
+
defaultLanguage: null,
|
|
2971
2983
|
};
|
|
2972
2984
|
},
|
|
2973
2985
|
addProseMirrorPlugins() {
|
|
@@ -2977,6 +2989,7 @@ const CodeBlockLowlight = CodeBlock.extend({
|
|
|
2977
2989
|
LowlightPlugin({
|
|
2978
2990
|
name: this.name,
|
|
2979
2991
|
lowlight: this.options.lowlight,
|
|
2992
|
+
defaultLanguage: this.options.defaultLanguage,
|
|
2980
2993
|
}),
|
|
2981
2994
|
];
|
|
2982
2995
|
},
|