@tiptap/extension-code-block-lowlight 2.0.0-beta.6 → 2.0.0-beta.63
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/LICENSE.md +1 -1
- package/README.md +2 -2
- 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 +86 -65
- package/dist/tiptap-extension-code-block-lowlight.cjs.js.map +1 -1
- package/dist/tiptap-extension-code-block-lowlight.esm.js +85 -65
- package/dist/tiptap-extension-code-block-lowlight.esm.js.map +1 -1
- package/dist/tiptap-extension-code-block-lowlight.umd.js +89 -68
- package/dist/tiptap-extension-code-block-lowlight.umd.js.map +1 -1
- package/package.json +11 -7
- package/src/code-block-lowlight.ts +10 -6
- package/src/lowlight-plugin.ts +28 -10
- package/CHANGELOG.md +0 -46
- package/dist/tiptap-extension-code-block-lowlight.bundle.umd.min.js +0 -2
- package/dist/tiptap-extension-code-block-lowlight.bundle.umd.min.js.map +0 -1
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/extension-code-block'), require('prosemirror-state'), require('prosemirror-view'), require('@tiptap/core')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', '@tiptap/extension-code-block', 'prosemirror-state', 'prosemirror-view', '@tiptap/core'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global[
|
|
5
|
-
}(this, (function (exports, CodeBlock, prosemirrorState, prosemirrorView, core$2) { 'use strict';
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-code-block-lowlight"] = {}, global.CodeBlock, global.prosemirrorState, global.prosemirrorView, global.core$2));
|
|
5
|
+
})(this, (function (exports, CodeBlock, prosemirrorState, prosemirrorView, core$2) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
9
9
|
var CodeBlock__default = /*#__PURE__*/_interopDefaultLegacy(CodeBlock);
|
|
10
10
|
|
|
11
|
+
var core$1 = {};
|
|
12
|
+
|
|
11
13
|
function deepFreeze(obj) {
|
|
12
14
|
if (obj instanceof Map) {
|
|
13
15
|
obj.clear = obj.delete = obj.set = function () {
|
|
@@ -1238,7 +1240,7 @@
|
|
|
1238
1240
|
return mode;
|
|
1239
1241
|
}
|
|
1240
1242
|
|
|
1241
|
-
var version = "10.7.
|
|
1243
|
+
var version = "10.7.3";
|
|
1242
1244
|
|
|
1243
1245
|
// @ts-nocheck
|
|
1244
1246
|
|
|
@@ -1470,6 +1472,11 @@
|
|
|
1470
1472
|
|
|
1471
1473
|
*/
|
|
1472
1474
|
|
|
1475
|
+
/**
|
|
1476
|
+
* @type {Record<string, boolean>}
|
|
1477
|
+
*/
|
|
1478
|
+
const seenDeprecations = {};
|
|
1479
|
+
|
|
1473
1480
|
/**
|
|
1474
1481
|
* @param {string} message
|
|
1475
1482
|
*/
|
|
@@ -1490,7 +1497,10 @@
|
|
|
1490
1497
|
* @param {string} message
|
|
1491
1498
|
*/
|
|
1492
1499
|
const deprecated = (version, message) => {
|
|
1500
|
+
if (seenDeprecations[`${version}/${message}`]) return;
|
|
1501
|
+
|
|
1493
1502
|
console.log(`Deprecated as of ${version}. ${message}`);
|
|
1503
|
+
seenDeprecations[`${version}/${message}`] = true;
|
|
1494
1504
|
};
|
|
1495
1505
|
|
|
1496
1506
|
/*
|
|
@@ -2516,14 +2526,11 @@
|
|
|
2516
2526
|
// export an "instance" of the highlighter
|
|
2517
2527
|
var highlight$1 = HLJS({});
|
|
2518
2528
|
|
|
2519
|
-
var core
|
|
2529
|
+
var core = highlight$1;
|
|
2520
2530
|
|
|
2521
|
-
|
|
2522
|
-
var module = { exports: {} };
|
|
2523
|
-
return fn(module, module.exports), module.exports;
|
|
2524
|
-
}
|
|
2531
|
+
var format = {exports: {}};
|
|
2525
2532
|
|
|
2526
|
-
|
|
2533
|
+
(function (module) {
|
|
2527
2534
|
(function() {
|
|
2528
2535
|
|
|
2529
2536
|
//// Export the API
|
|
@@ -2635,20 +2642,22 @@
|
|
|
2635
2642
|
}
|
|
2636
2643
|
|
|
2637
2644
|
}());
|
|
2638
|
-
});
|
|
2645
|
+
}(format));
|
|
2646
|
+
|
|
2647
|
+
var formatter = format.exports;
|
|
2639
2648
|
|
|
2640
|
-
var fault = create(Error);
|
|
2649
|
+
var fault$1 = create(Error);
|
|
2641
2650
|
|
|
2642
|
-
var fault_1 = fault;
|
|
2651
|
+
var fault_1 = fault$1;
|
|
2643
2652
|
|
|
2644
|
-
fault.eval = create(EvalError);
|
|
2645
|
-
fault.range = create(RangeError);
|
|
2646
|
-
fault.reference = create(ReferenceError);
|
|
2647
|
-
fault.syntax = create(SyntaxError);
|
|
2648
|
-
fault.type = create(TypeError);
|
|
2649
|
-
fault.uri = create(URIError);
|
|
2653
|
+
fault$1.eval = create(EvalError);
|
|
2654
|
+
fault$1.range = create(RangeError);
|
|
2655
|
+
fault$1.reference = create(ReferenceError);
|
|
2656
|
+
fault$1.syntax = create(SyntaxError);
|
|
2657
|
+
fault$1.type = create(TypeError);
|
|
2658
|
+
fault$1.uri = create(URIError);
|
|
2650
2659
|
|
|
2651
|
-
fault.create = create;
|
|
2660
|
+
fault$1.create = create;
|
|
2652
2661
|
|
|
2653
2662
|
// Create a new `EConstructor`, with the formatted `format` as a first argument.
|
|
2654
2663
|
function create(EConstructor) {
|
|
@@ -2656,20 +2665,23 @@
|
|
|
2656
2665
|
|
|
2657
2666
|
return FormattedError
|
|
2658
2667
|
|
|
2659
|
-
function FormattedError(format
|
|
2660
|
-
if (format
|
|
2661
|
-
format
|
|
2668
|
+
function FormattedError(format) {
|
|
2669
|
+
if (format) {
|
|
2670
|
+
format = formatter.apply(null, arguments);
|
|
2662
2671
|
}
|
|
2663
2672
|
|
|
2664
|
-
return new EConstructor(format
|
|
2673
|
+
return new EConstructor(format)
|
|
2665
2674
|
}
|
|
2666
2675
|
}
|
|
2667
2676
|
|
|
2668
|
-
var
|
|
2669
|
-
var
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2677
|
+
var high = core;
|
|
2678
|
+
var fault = fault_1;
|
|
2679
|
+
|
|
2680
|
+
core$1.highlight = highlight;
|
|
2681
|
+
core$1.highlightAuto = highlightAuto;
|
|
2682
|
+
core$1.registerLanguage = registerLanguage;
|
|
2683
|
+
core$1.listLanguages = listLanguages;
|
|
2684
|
+
core$1.registerAlias = registerAlias;
|
|
2673
2685
|
|
|
2674
2686
|
Emitter.prototype.addText = text;
|
|
2675
2687
|
Emitter.prototype.addKeyword = addKeyword;
|
|
@@ -2684,32 +2696,32 @@
|
|
|
2684
2696
|
|
|
2685
2697
|
// Highlighting `value` in the language `name`.
|
|
2686
2698
|
function highlight(name, value, options) {
|
|
2687
|
-
var before =
|
|
2699
|
+
var before = high.configure({});
|
|
2688
2700
|
var settings = options || {};
|
|
2689
2701
|
var prefix = settings.prefix;
|
|
2690
2702
|
var result;
|
|
2691
2703
|
|
|
2692
2704
|
if (typeof name !== 'string') {
|
|
2693
|
-
throw
|
|
2705
|
+
throw fault('Expected `string` for name, got `%s`', name)
|
|
2694
2706
|
}
|
|
2695
2707
|
|
|
2696
|
-
if (!
|
|
2697
|
-
throw
|
|
2708
|
+
if (!high.getLanguage(name)) {
|
|
2709
|
+
throw fault('Unknown language: `%s` is not registered', name)
|
|
2698
2710
|
}
|
|
2699
2711
|
|
|
2700
2712
|
if (typeof value !== 'string') {
|
|
2701
|
-
throw
|
|
2713
|
+
throw fault('Expected `string` for value, got `%s`', value)
|
|
2702
2714
|
}
|
|
2703
2715
|
|
|
2704
2716
|
if (prefix === null || prefix === undefined) {
|
|
2705
2717
|
prefix = defaultPrefix;
|
|
2706
2718
|
}
|
|
2707
2719
|
|
|
2708
|
-
|
|
2720
|
+
high.configure({__emitter: Emitter, classPrefix: prefix});
|
|
2709
2721
|
|
|
2710
|
-
result =
|
|
2722
|
+
result = high.highlight(value, {language: name, ignoreIllegals: true});
|
|
2711
2723
|
|
|
2712
|
-
|
|
2724
|
+
high.configure(before || {});
|
|
2713
2725
|
|
|
2714
2726
|
/* istanbul ignore if - Highlight.js seems to use this (currently) for broken
|
|
2715
2727
|
* grammars, so let’s keep it in there just to be sure. */
|
|
@@ -2726,7 +2738,7 @@
|
|
|
2726
2738
|
|
|
2727
2739
|
function highlightAuto(value, options) {
|
|
2728
2740
|
var settings = options || {};
|
|
2729
|
-
var subset = settings.subset ||
|
|
2741
|
+
var subset = settings.subset || high.listLanguages();
|
|
2730
2742
|
settings.prefix;
|
|
2731
2743
|
var length = subset.length;
|
|
2732
2744
|
var index = -1;
|
|
@@ -2736,7 +2748,7 @@
|
|
|
2736
2748
|
var name;
|
|
2737
2749
|
|
|
2738
2750
|
if (typeof value !== 'string') {
|
|
2739
|
-
throw
|
|
2751
|
+
throw fault('Expected `string` for value, got `%s`', value)
|
|
2740
2752
|
}
|
|
2741
2753
|
|
|
2742
2754
|
secondBest = {relevance: 0, language: null, value: []};
|
|
@@ -2745,7 +2757,7 @@
|
|
|
2745
2757
|
while (++index < length) {
|
|
2746
2758
|
name = subset[index];
|
|
2747
2759
|
|
|
2748
|
-
if (!
|
|
2760
|
+
if (!high.getLanguage(name)) {
|
|
2749
2761
|
continue
|
|
2750
2762
|
}
|
|
2751
2763
|
|
|
@@ -2771,12 +2783,12 @@
|
|
|
2771
2783
|
|
|
2772
2784
|
// Register a language.
|
|
2773
2785
|
function registerLanguage(name, syntax) {
|
|
2774
|
-
|
|
2786
|
+
high.registerLanguage(name, syntax);
|
|
2775
2787
|
}
|
|
2776
2788
|
|
|
2777
2789
|
// Get a list of all registered languages.
|
|
2778
2790
|
function listLanguages() {
|
|
2779
|
-
return
|
|
2791
|
+
return high.listLanguages()
|
|
2780
2792
|
}
|
|
2781
2793
|
|
|
2782
2794
|
// Register more aliases for an already registered language.
|
|
@@ -2790,7 +2802,7 @@
|
|
|
2790
2802
|
}
|
|
2791
2803
|
|
|
2792
2804
|
for (key in map) {
|
|
2793
|
-
|
|
2805
|
+
high.registerAliases(map[key], {languageName: key});
|
|
2794
2806
|
}
|
|
2795
2807
|
}
|
|
2796
2808
|
|
|
@@ -2864,14 +2876,6 @@
|
|
|
2864
2876
|
|
|
2865
2877
|
function noop() {}
|
|
2866
2878
|
|
|
2867
|
-
var core = {
|
|
2868
|
-
highlight: highlight_1,
|
|
2869
|
-
highlightAuto: highlightAuto_1,
|
|
2870
|
-
registerLanguage: registerLanguage_1,
|
|
2871
|
-
listLanguages: listLanguages_1,
|
|
2872
|
-
registerAlias: registerAlias_1
|
|
2873
|
-
};
|
|
2874
|
-
|
|
2875
2879
|
function parseNodes(nodes, className = []) {
|
|
2876
2880
|
return nodes
|
|
2877
2881
|
.map(node => {
|
|
@@ -2891,18 +2895,20 @@
|
|
|
2891
2895
|
})
|
|
2892
2896
|
.flat();
|
|
2893
2897
|
}
|
|
2894
|
-
function
|
|
2898
|
+
function getHighlightNodes(result) {
|
|
2899
|
+
// `.value` for lowlight v1, `.children` for lowlight v2
|
|
2900
|
+
return result.value || result.children || [];
|
|
2901
|
+
}
|
|
2902
|
+
function getDecorations({ doc, name, lowlight, defaultLanguage, }) {
|
|
2895
2903
|
const decorations = [];
|
|
2896
2904
|
core$2.findChildren(doc, node => node.type.name === name)
|
|
2897
2905
|
.forEach(block => {
|
|
2898
2906
|
let from = block.pos + 1;
|
|
2899
|
-
const
|
|
2900
|
-
// TODO: add missing type for `listLanguages`
|
|
2901
|
-
// @ts-ignore
|
|
2907
|
+
const language = block.node.attrs.language || defaultLanguage;
|
|
2902
2908
|
const languages = lowlight.listLanguages();
|
|
2903
2909
|
const nodes = language && languages.includes(language)
|
|
2904
|
-
? lowlight.highlight(language, block.node.textContent)
|
|
2905
|
-
: lowlight.highlightAuto(block.node.textContent)
|
|
2910
|
+
? getHighlightNodes(lowlight.highlight(language, block.node.textContent))
|
|
2911
|
+
: getHighlightNodes(lowlight.highlightAuto(block.node.textContent));
|
|
2906
2912
|
parseNodes(nodes).forEach(node => {
|
|
2907
2913
|
const to = from + node.text.length;
|
|
2908
2914
|
if (node.classes.length) {
|
|
@@ -2916,11 +2922,16 @@
|
|
|
2916
2922
|
});
|
|
2917
2923
|
return prosemirrorView.DecorationSet.create(doc, decorations);
|
|
2918
2924
|
}
|
|
2919
|
-
function LowlightPlugin({ name, lowlight }) {
|
|
2925
|
+
function LowlightPlugin({ name, lowlight, defaultLanguage }) {
|
|
2920
2926
|
return new prosemirrorState.Plugin({
|
|
2921
2927
|
key: new prosemirrorState.PluginKey('lowlight'),
|
|
2922
2928
|
state: {
|
|
2923
|
-
init: (_, { doc }) => getDecorations({
|
|
2929
|
+
init: (_, { doc }) => getDecorations({
|
|
2930
|
+
doc,
|
|
2931
|
+
name,
|
|
2932
|
+
lowlight,
|
|
2933
|
+
defaultLanguage,
|
|
2934
|
+
}),
|
|
2924
2935
|
apply: (transaction, decorationSet, oldState, newState) => {
|
|
2925
2936
|
const oldNodeName = oldState.selection.$head.parent.type.name;
|
|
2926
2937
|
const newNodeName = newState.selection.$head.parent.type.name;
|
|
@@ -2948,7 +2959,12 @@
|
|
|
2948
2959
|
&& node.pos + node.node.nodeSize <= step.to;
|
|
2949
2960
|
});
|
|
2950
2961
|
}))) {
|
|
2951
|
-
return getDecorations({
|
|
2962
|
+
return getDecorations({
|
|
2963
|
+
doc: transaction.doc,
|
|
2964
|
+
name,
|
|
2965
|
+
lowlight,
|
|
2966
|
+
defaultLanguage,
|
|
2967
|
+
});
|
|
2952
2968
|
}
|
|
2953
2969
|
return decorationSet.map(transaction.mapping, transaction.doc);
|
|
2954
2970
|
},
|
|
@@ -2961,27 +2977,32 @@
|
|
|
2961
2977
|
});
|
|
2962
2978
|
}
|
|
2963
2979
|
|
|
2964
|
-
const CodeBlockLowlight = CodeBlock__default[
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2980
|
+
const CodeBlockLowlight = CodeBlock__default["default"].extend({
|
|
2981
|
+
addOptions() {
|
|
2982
|
+
var _a;
|
|
2983
|
+
return {
|
|
2984
|
+
...(_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this),
|
|
2985
|
+
lowlight: core$1,
|
|
2986
|
+
defaultLanguage: null,
|
|
2987
|
+
};
|
|
2968
2988
|
},
|
|
2969
2989
|
addProseMirrorPlugins() {
|
|
2990
|
+
var _a;
|
|
2970
2991
|
return [
|
|
2971
|
-
|
|
2972
|
-
// ...this.parentConfig.addProseMirrorPlugins?.() || [],
|
|
2992
|
+
...((_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this)) || [],
|
|
2973
2993
|
LowlightPlugin({
|
|
2974
|
-
name:
|
|
2994
|
+
name: this.name,
|
|
2975
2995
|
lowlight: this.options.lowlight,
|
|
2996
|
+
defaultLanguage: this.options.defaultLanguage,
|
|
2976
2997
|
}),
|
|
2977
2998
|
];
|
|
2978
2999
|
},
|
|
2979
3000
|
});
|
|
2980
3001
|
|
|
2981
3002
|
exports.CodeBlockLowlight = CodeBlockLowlight;
|
|
2982
|
-
exports
|
|
3003
|
+
exports["default"] = CodeBlockLowlight;
|
|
2983
3004
|
|
|
2984
3005
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2985
3006
|
|
|
2986
|
-
}))
|
|
3007
|
+
}));
|
|
2987
3008
|
//# sourceMappingURL=tiptap-extension-code-block-lowlight.umd.js.map
|