@tiptap/extension-code-block-lowlight 2.0.0-beta.47 → 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 +2 -1
- package/dist/packages/extension-code-block-lowlight/src/lowlight-plugin.d.ts +2 -1
- package/dist/tiptap-extension-code-block-lowlight.cjs.js +24 -8
- package/dist/tiptap-extension-code-block-lowlight.cjs.js.map +1 -1
- package/dist/tiptap-extension-code-block-lowlight.esm.js +24 -8
- package/dist/tiptap-extension-code-block-lowlight.esm.js.map +1 -1
- package/dist/tiptap-extension-code-block-lowlight.umd.js +24 -8
- package/dist/tiptap-extension-code-block-lowlight.umd.js.map +1 -1
- package/package.json +5 -5
- package/src/code-block-lowlight.ts +8 -3
- package/src/lowlight-plugin.ts +21 -5
|
@@ -2899,12 +2899,13 @@
|
|
|
2899
2899
|
// `.value` for lowlight v1, `.children` for lowlight v2
|
|
2900
2900
|
return result.value || result.children || [];
|
|
2901
2901
|
}
|
|
2902
|
-
function getDecorations({ doc, name, lowlight }) {
|
|
2902
|
+
function getDecorations({ doc, name, lowlight, defaultLanguage, }) {
|
|
2903
2903
|
const decorations = [];
|
|
2904
2904
|
core$2.findChildren(doc, node => node.type.name === name)
|
|
2905
2905
|
.forEach(block => {
|
|
2906
2906
|
let from = block.pos + 1;
|
|
2907
|
-
const
|
|
2907
|
+
const language = block.node.attrs.language || defaultLanguage;
|
|
2908
|
+
console.log({ language, defaultLanguage });
|
|
2908
2909
|
const languages = lowlight.listLanguages();
|
|
2909
2910
|
const nodes = language && languages.includes(language)
|
|
2910
2911
|
? getHighlightNodes(lowlight.highlight(language, block.node.textContent))
|
|
@@ -2922,11 +2923,16 @@
|
|
|
2922
2923
|
});
|
|
2923
2924
|
return prosemirrorView.DecorationSet.create(doc, decorations);
|
|
2924
2925
|
}
|
|
2925
|
-
function LowlightPlugin({ name, lowlight }) {
|
|
2926
|
+
function LowlightPlugin({ name, lowlight, defaultLanguage }) {
|
|
2926
2927
|
return new prosemirrorState.Plugin({
|
|
2927
2928
|
key: new prosemirrorState.PluginKey('lowlight'),
|
|
2928
2929
|
state: {
|
|
2929
|
-
init: (_, { doc }) => getDecorations({
|
|
2930
|
+
init: (_, { doc }) => getDecorations({
|
|
2931
|
+
doc,
|
|
2932
|
+
name,
|
|
2933
|
+
lowlight,
|
|
2934
|
+
defaultLanguage,
|
|
2935
|
+
}),
|
|
2930
2936
|
apply: (transaction, decorationSet, oldState, newState) => {
|
|
2931
2937
|
const oldNodeName = oldState.selection.$head.parent.type.name;
|
|
2932
2938
|
const newNodeName = newState.selection.$head.parent.type.name;
|
|
@@ -2954,7 +2960,12 @@
|
|
|
2954
2960
|
&& node.pos + node.node.nodeSize <= step.to;
|
|
2955
2961
|
});
|
|
2956
2962
|
}))) {
|
|
2957
|
-
return getDecorations({
|
|
2963
|
+
return getDecorations({
|
|
2964
|
+
doc: transaction.doc,
|
|
2965
|
+
name,
|
|
2966
|
+
lowlight,
|
|
2967
|
+
defaultLanguage,
|
|
2968
|
+
});
|
|
2958
2969
|
}
|
|
2959
2970
|
return decorationSet.map(transaction.mapping, transaction.doc);
|
|
2960
2971
|
},
|
|
@@ -2968,9 +2979,13 @@
|
|
|
2968
2979
|
}
|
|
2969
2980
|
|
|
2970
2981
|
const CodeBlockLowlight = CodeBlock__default["default"].extend({
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2982
|
+
addOptions() {
|
|
2983
|
+
var _a;
|
|
2984
|
+
return {
|
|
2985
|
+
...(_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this),
|
|
2986
|
+
lowlight: core$1,
|
|
2987
|
+
defaultLanguage: null,
|
|
2988
|
+
};
|
|
2974
2989
|
},
|
|
2975
2990
|
addProseMirrorPlugins() {
|
|
2976
2991
|
var _a;
|
|
@@ -2979,6 +2994,7 @@
|
|
|
2979
2994
|
LowlightPlugin({
|
|
2980
2995
|
name: this.name,
|
|
2981
2996
|
lowlight: this.options.lowlight,
|
|
2997
|
+
defaultLanguage: this.options.defaultLanguage,
|
|
2982
2998
|
}),
|
|
2983
2999
|
];
|
|
2984
3000
|
},
|