@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
|
@@ -3,6 +3,8 @@ import { Plugin, PluginKey } from 'prosemirror-state';
|
|
|
3
3
|
import { DecorationSet, Decoration } from 'prosemirror-view';
|
|
4
4
|
import { findChildren } from '@tiptap/core';
|
|
5
5
|
|
|
6
|
+
var core$1 = {};
|
|
7
|
+
|
|
6
8
|
function deepFreeze(obj) {
|
|
7
9
|
if (obj instanceof Map) {
|
|
8
10
|
obj.clear = obj.delete = obj.set = function () {
|
|
@@ -1233,7 +1235,7 @@ function expandOrCloneMode(mode) {
|
|
|
1233
1235
|
return mode;
|
|
1234
1236
|
}
|
|
1235
1237
|
|
|
1236
|
-
var version = "10.7.
|
|
1238
|
+
var version = "10.7.3";
|
|
1237
1239
|
|
|
1238
1240
|
// @ts-nocheck
|
|
1239
1241
|
|
|
@@ -1465,6 +1467,11 @@ https://github.com/highlightjs/highlight.js/issues/2880#issuecomment-747275419
|
|
|
1465
1467
|
|
|
1466
1468
|
*/
|
|
1467
1469
|
|
|
1470
|
+
/**
|
|
1471
|
+
* @type {Record<string, boolean>}
|
|
1472
|
+
*/
|
|
1473
|
+
const seenDeprecations = {};
|
|
1474
|
+
|
|
1468
1475
|
/**
|
|
1469
1476
|
* @param {string} message
|
|
1470
1477
|
*/
|
|
@@ -1485,7 +1492,10 @@ const warn = (message, ...args) => {
|
|
|
1485
1492
|
* @param {string} message
|
|
1486
1493
|
*/
|
|
1487
1494
|
const deprecated = (version, message) => {
|
|
1495
|
+
if (seenDeprecations[`${version}/${message}`]) return;
|
|
1496
|
+
|
|
1488
1497
|
console.log(`Deprecated as of ${version}. ${message}`);
|
|
1498
|
+
seenDeprecations[`${version}/${message}`] = true;
|
|
1489
1499
|
};
|
|
1490
1500
|
|
|
1491
1501
|
/*
|
|
@@ -2511,14 +2521,11 @@ const HLJS = function(hljs) {
|
|
|
2511
2521
|
// export an "instance" of the highlighter
|
|
2512
2522
|
var highlight$1 = HLJS({});
|
|
2513
2523
|
|
|
2514
|
-
var core
|
|
2524
|
+
var core = highlight$1;
|
|
2515
2525
|
|
|
2516
|
-
|
|
2517
|
-
var module = { exports: {} };
|
|
2518
|
-
return fn(module, module.exports), module.exports;
|
|
2519
|
-
}
|
|
2526
|
+
var format = {exports: {}};
|
|
2520
2527
|
|
|
2521
|
-
|
|
2528
|
+
(function (module) {
|
|
2522
2529
|
(function() {
|
|
2523
2530
|
|
|
2524
2531
|
//// Export the API
|
|
@@ -2630,20 +2637,22 @@ var format = createCommonjsModule(function (module) {
|
|
|
2630
2637
|
}
|
|
2631
2638
|
|
|
2632
2639
|
}());
|
|
2633
|
-
});
|
|
2640
|
+
}(format));
|
|
2641
|
+
|
|
2642
|
+
var formatter = format.exports;
|
|
2634
2643
|
|
|
2635
|
-
var fault = create(Error);
|
|
2644
|
+
var fault$1 = create(Error);
|
|
2636
2645
|
|
|
2637
|
-
var fault_1 = fault;
|
|
2646
|
+
var fault_1 = fault$1;
|
|
2638
2647
|
|
|
2639
|
-
fault.eval = create(EvalError);
|
|
2640
|
-
fault.range = create(RangeError);
|
|
2641
|
-
fault.reference = create(ReferenceError);
|
|
2642
|
-
fault.syntax = create(SyntaxError);
|
|
2643
|
-
fault.type = create(TypeError);
|
|
2644
|
-
fault.uri = create(URIError);
|
|
2648
|
+
fault$1.eval = create(EvalError);
|
|
2649
|
+
fault$1.range = create(RangeError);
|
|
2650
|
+
fault$1.reference = create(ReferenceError);
|
|
2651
|
+
fault$1.syntax = create(SyntaxError);
|
|
2652
|
+
fault$1.type = create(TypeError);
|
|
2653
|
+
fault$1.uri = create(URIError);
|
|
2645
2654
|
|
|
2646
|
-
fault.create = create;
|
|
2655
|
+
fault$1.create = create;
|
|
2647
2656
|
|
|
2648
2657
|
// Create a new `EConstructor`, with the formatted `format` as a first argument.
|
|
2649
2658
|
function create(EConstructor) {
|
|
@@ -2651,20 +2660,23 @@ function create(EConstructor) {
|
|
|
2651
2660
|
|
|
2652
2661
|
return FormattedError
|
|
2653
2662
|
|
|
2654
|
-
function FormattedError(format
|
|
2655
|
-
if (format
|
|
2656
|
-
format
|
|
2663
|
+
function FormattedError(format) {
|
|
2664
|
+
if (format) {
|
|
2665
|
+
format = formatter.apply(null, arguments);
|
|
2657
2666
|
}
|
|
2658
2667
|
|
|
2659
|
-
return new EConstructor(format
|
|
2668
|
+
return new EConstructor(format)
|
|
2660
2669
|
}
|
|
2661
2670
|
}
|
|
2662
2671
|
|
|
2663
|
-
var
|
|
2664
|
-
var
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2672
|
+
var high = core;
|
|
2673
|
+
var fault = fault_1;
|
|
2674
|
+
|
|
2675
|
+
core$1.highlight = highlight;
|
|
2676
|
+
core$1.highlightAuto = highlightAuto;
|
|
2677
|
+
core$1.registerLanguage = registerLanguage;
|
|
2678
|
+
core$1.listLanguages = listLanguages;
|
|
2679
|
+
core$1.registerAlias = registerAlias;
|
|
2668
2680
|
|
|
2669
2681
|
Emitter.prototype.addText = text;
|
|
2670
2682
|
Emitter.prototype.addKeyword = addKeyword;
|
|
@@ -2679,32 +2691,32 @@ var defaultPrefix = 'hljs-';
|
|
|
2679
2691
|
|
|
2680
2692
|
// Highlighting `value` in the language `name`.
|
|
2681
2693
|
function highlight(name, value, options) {
|
|
2682
|
-
var before =
|
|
2694
|
+
var before = high.configure({});
|
|
2683
2695
|
var settings = options || {};
|
|
2684
2696
|
var prefix = settings.prefix;
|
|
2685
2697
|
var result;
|
|
2686
2698
|
|
|
2687
2699
|
if (typeof name !== 'string') {
|
|
2688
|
-
throw
|
|
2700
|
+
throw fault('Expected `string` for name, got `%s`', name)
|
|
2689
2701
|
}
|
|
2690
2702
|
|
|
2691
|
-
if (!
|
|
2692
|
-
throw
|
|
2703
|
+
if (!high.getLanguage(name)) {
|
|
2704
|
+
throw fault('Unknown language: `%s` is not registered', name)
|
|
2693
2705
|
}
|
|
2694
2706
|
|
|
2695
2707
|
if (typeof value !== 'string') {
|
|
2696
|
-
throw
|
|
2708
|
+
throw fault('Expected `string` for value, got `%s`', value)
|
|
2697
2709
|
}
|
|
2698
2710
|
|
|
2699
2711
|
if (prefix === null || prefix === undefined) {
|
|
2700
2712
|
prefix = defaultPrefix;
|
|
2701
2713
|
}
|
|
2702
2714
|
|
|
2703
|
-
|
|
2715
|
+
high.configure({__emitter: Emitter, classPrefix: prefix});
|
|
2704
2716
|
|
|
2705
|
-
result =
|
|
2717
|
+
result = high.highlight(value, {language: name, ignoreIllegals: true});
|
|
2706
2718
|
|
|
2707
|
-
|
|
2719
|
+
high.configure(before || {});
|
|
2708
2720
|
|
|
2709
2721
|
/* istanbul ignore if - Highlight.js seems to use this (currently) for broken
|
|
2710
2722
|
* grammars, so let’s keep it in there just to be sure. */
|
|
@@ -2721,7 +2733,7 @@ function highlight(name, value, options) {
|
|
|
2721
2733
|
|
|
2722
2734
|
function highlightAuto(value, options) {
|
|
2723
2735
|
var settings = options || {};
|
|
2724
|
-
var subset = settings.subset ||
|
|
2736
|
+
var subset = settings.subset || high.listLanguages();
|
|
2725
2737
|
settings.prefix;
|
|
2726
2738
|
var length = subset.length;
|
|
2727
2739
|
var index = -1;
|
|
@@ -2731,7 +2743,7 @@ function highlightAuto(value, options) {
|
|
|
2731
2743
|
var name;
|
|
2732
2744
|
|
|
2733
2745
|
if (typeof value !== 'string') {
|
|
2734
|
-
throw
|
|
2746
|
+
throw fault('Expected `string` for value, got `%s`', value)
|
|
2735
2747
|
}
|
|
2736
2748
|
|
|
2737
2749
|
secondBest = {relevance: 0, language: null, value: []};
|
|
@@ -2740,7 +2752,7 @@ function highlightAuto(value, options) {
|
|
|
2740
2752
|
while (++index < length) {
|
|
2741
2753
|
name = subset[index];
|
|
2742
2754
|
|
|
2743
|
-
if (!
|
|
2755
|
+
if (!high.getLanguage(name)) {
|
|
2744
2756
|
continue
|
|
2745
2757
|
}
|
|
2746
2758
|
|
|
@@ -2766,12 +2778,12 @@ function highlightAuto(value, options) {
|
|
|
2766
2778
|
|
|
2767
2779
|
// Register a language.
|
|
2768
2780
|
function registerLanguage(name, syntax) {
|
|
2769
|
-
|
|
2781
|
+
high.registerLanguage(name, syntax);
|
|
2770
2782
|
}
|
|
2771
2783
|
|
|
2772
2784
|
// Get a list of all registered languages.
|
|
2773
2785
|
function listLanguages() {
|
|
2774
|
-
return
|
|
2786
|
+
return high.listLanguages()
|
|
2775
2787
|
}
|
|
2776
2788
|
|
|
2777
2789
|
// Register more aliases for an already registered language.
|
|
@@ -2785,7 +2797,7 @@ function registerAlias(name, alias) {
|
|
|
2785
2797
|
}
|
|
2786
2798
|
|
|
2787
2799
|
for (key in map) {
|
|
2788
|
-
|
|
2800
|
+
high.registerAliases(map[key], {languageName: key});
|
|
2789
2801
|
}
|
|
2790
2802
|
}
|
|
2791
2803
|
|
|
@@ -2859,14 +2871,6 @@ function toHtmlNoop() {
|
|
|
2859
2871
|
|
|
2860
2872
|
function noop() {}
|
|
2861
2873
|
|
|
2862
|
-
var core = {
|
|
2863
|
-
highlight: highlight_1,
|
|
2864
|
-
highlightAuto: highlightAuto_1,
|
|
2865
|
-
registerLanguage: registerLanguage_1,
|
|
2866
|
-
listLanguages: listLanguages_1,
|
|
2867
|
-
registerAlias: registerAlias_1
|
|
2868
|
-
};
|
|
2869
|
-
|
|
2870
2874
|
function parseNodes(nodes, className = []) {
|
|
2871
2875
|
return nodes
|
|
2872
2876
|
.map(node => {
|
|
@@ -2886,18 +2890,20 @@ function parseNodes(nodes, className = []) {
|
|
|
2886
2890
|
})
|
|
2887
2891
|
.flat();
|
|
2888
2892
|
}
|
|
2889
|
-
function
|
|
2893
|
+
function getHighlightNodes(result) {
|
|
2894
|
+
// `.value` for lowlight v1, `.children` for lowlight v2
|
|
2895
|
+
return result.value || result.children || [];
|
|
2896
|
+
}
|
|
2897
|
+
function getDecorations({ doc, name, lowlight, defaultLanguage, }) {
|
|
2890
2898
|
const decorations = [];
|
|
2891
2899
|
findChildren(doc, node => node.type.name === name)
|
|
2892
2900
|
.forEach(block => {
|
|
2893
2901
|
let from = block.pos + 1;
|
|
2894
|
-
const
|
|
2895
|
-
// TODO: add missing type for `listLanguages`
|
|
2896
|
-
// @ts-ignore
|
|
2902
|
+
const language = block.node.attrs.language || defaultLanguage;
|
|
2897
2903
|
const languages = lowlight.listLanguages();
|
|
2898
2904
|
const nodes = language && languages.includes(language)
|
|
2899
|
-
? lowlight.highlight(language, block.node.textContent)
|
|
2900
|
-
: lowlight.highlightAuto(block.node.textContent)
|
|
2905
|
+
? getHighlightNodes(lowlight.highlight(language, block.node.textContent))
|
|
2906
|
+
: getHighlightNodes(lowlight.highlightAuto(block.node.textContent));
|
|
2901
2907
|
parseNodes(nodes).forEach(node => {
|
|
2902
2908
|
const to = from + node.text.length;
|
|
2903
2909
|
if (node.classes.length) {
|
|
@@ -2911,11 +2917,16 @@ function getDecorations({ doc, name, lowlight }) {
|
|
|
2911
2917
|
});
|
|
2912
2918
|
return DecorationSet.create(doc, decorations);
|
|
2913
2919
|
}
|
|
2914
|
-
function LowlightPlugin({ name, lowlight }) {
|
|
2920
|
+
function LowlightPlugin({ name, lowlight, defaultLanguage }) {
|
|
2915
2921
|
return new Plugin({
|
|
2916
2922
|
key: new PluginKey('lowlight'),
|
|
2917
2923
|
state: {
|
|
2918
|
-
init: (_, { doc }) => getDecorations({
|
|
2924
|
+
init: (_, { doc }) => getDecorations({
|
|
2925
|
+
doc,
|
|
2926
|
+
name,
|
|
2927
|
+
lowlight,
|
|
2928
|
+
defaultLanguage,
|
|
2929
|
+
}),
|
|
2919
2930
|
apply: (transaction, decorationSet, oldState, newState) => {
|
|
2920
2931
|
const oldNodeName = oldState.selection.$head.parent.type.name;
|
|
2921
2932
|
const newNodeName = newState.selection.$head.parent.type.name;
|
|
@@ -2943,7 +2954,12 @@ function LowlightPlugin({ name, lowlight }) {
|
|
|
2943
2954
|
&& node.pos + node.node.nodeSize <= step.to;
|
|
2944
2955
|
});
|
|
2945
2956
|
}))) {
|
|
2946
|
-
return getDecorations({
|
|
2957
|
+
return getDecorations({
|
|
2958
|
+
doc: transaction.doc,
|
|
2959
|
+
name,
|
|
2960
|
+
lowlight,
|
|
2961
|
+
defaultLanguage,
|
|
2962
|
+
});
|
|
2947
2963
|
}
|
|
2948
2964
|
return decorationSet.map(transaction.mapping, transaction.doc);
|
|
2949
2965
|
},
|
|
@@ -2957,22 +2973,26 @@ function LowlightPlugin({ name, lowlight }) {
|
|
|
2957
2973
|
}
|
|
2958
2974
|
|
|
2959
2975
|
const CodeBlockLowlight = CodeBlock.extend({
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2976
|
+
addOptions() {
|
|
2977
|
+
var _a;
|
|
2978
|
+
return {
|
|
2979
|
+
...(_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this),
|
|
2980
|
+
lowlight: core$1,
|
|
2981
|
+
defaultLanguage: null,
|
|
2982
|
+
};
|
|
2963
2983
|
},
|
|
2964
2984
|
addProseMirrorPlugins() {
|
|
2985
|
+
var _a;
|
|
2965
2986
|
return [
|
|
2966
|
-
|
|
2967
|
-
// ...this.parentConfig.addProseMirrorPlugins?.() || [],
|
|
2987
|
+
...((_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this)) || [],
|
|
2968
2988
|
LowlightPlugin({
|
|
2969
|
-
name:
|
|
2989
|
+
name: this.name,
|
|
2970
2990
|
lowlight: this.options.lowlight,
|
|
2991
|
+
defaultLanguage: this.options.defaultLanguage,
|
|
2971
2992
|
}),
|
|
2972
2993
|
];
|
|
2973
2994
|
},
|
|
2974
2995
|
});
|
|
2975
2996
|
|
|
2976
|
-
export default
|
|
2977
|
-
export { CodeBlockLowlight };
|
|
2997
|
+
export { CodeBlockLowlight, CodeBlockLowlight as default };
|
|
2978
2998
|
//# sourceMappingURL=tiptap-extension-code-block-lowlight.esm.js.map
|