@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
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
## Introduction
|
|
8
8
|
tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as *New York Times*, *The Guardian* or *Atlassian*.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Official Documentation
|
|
11
11
|
Documentation can be found on the [tiptap website](https://tiptap.dev).
|
|
12
12
|
|
|
13
13
|
## License
|
|
14
|
-
tiptap is open
|
|
14
|
+
tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CodeBlockOptions } from '@tiptap/extension-code-block';
|
|
2
2
|
export interface CodeBlockLowlightOptions extends CodeBlockOptions {
|
|
3
3
|
lowlight: any;
|
|
4
|
+
defaultLanguage: string | null | undefined;
|
|
4
5
|
}
|
|
5
|
-
export declare const CodeBlockLowlight: import("@tiptap/core").Node<CodeBlockLowlightOptions>;
|
|
6
|
+
export declare const CodeBlockLowlight: import("@tiptap/core").Node<CodeBlockLowlightOptions, any>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Plugin } from 'prosemirror-state';
|
|
2
|
-
export declare function LowlightPlugin({ name, lowlight }: {
|
|
2
|
+
export declare function LowlightPlugin({ name, lowlight, defaultLanguage }: {
|
|
3
3
|
name: string;
|
|
4
4
|
lowlight: any;
|
|
5
|
+
defaultLanguage: string | null | undefined;
|
|
5
6
|
}): Plugin<any, any>;
|
|
@@ -11,6 +11,8 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
11
11
|
|
|
12
12
|
var CodeBlock__default = /*#__PURE__*/_interopDefaultLegacy(CodeBlock);
|
|
13
13
|
|
|
14
|
+
var core$1 = {};
|
|
15
|
+
|
|
14
16
|
function deepFreeze(obj) {
|
|
15
17
|
if (obj instanceof Map) {
|
|
16
18
|
obj.clear = obj.delete = obj.set = function () {
|
|
@@ -1241,7 +1243,7 @@ function expandOrCloneMode(mode) {
|
|
|
1241
1243
|
return mode;
|
|
1242
1244
|
}
|
|
1243
1245
|
|
|
1244
|
-
var version = "10.7.
|
|
1246
|
+
var version = "10.7.3";
|
|
1245
1247
|
|
|
1246
1248
|
// @ts-nocheck
|
|
1247
1249
|
|
|
@@ -1473,6 +1475,11 @@ https://github.com/highlightjs/highlight.js/issues/2880#issuecomment-747275419
|
|
|
1473
1475
|
|
|
1474
1476
|
*/
|
|
1475
1477
|
|
|
1478
|
+
/**
|
|
1479
|
+
* @type {Record<string, boolean>}
|
|
1480
|
+
*/
|
|
1481
|
+
const seenDeprecations = {};
|
|
1482
|
+
|
|
1476
1483
|
/**
|
|
1477
1484
|
* @param {string} message
|
|
1478
1485
|
*/
|
|
@@ -1493,7 +1500,10 @@ const warn = (message, ...args) => {
|
|
|
1493
1500
|
* @param {string} message
|
|
1494
1501
|
*/
|
|
1495
1502
|
const deprecated = (version, message) => {
|
|
1503
|
+
if (seenDeprecations[`${version}/${message}`]) return;
|
|
1504
|
+
|
|
1496
1505
|
console.log(`Deprecated as of ${version}. ${message}`);
|
|
1506
|
+
seenDeprecations[`${version}/${message}`] = true;
|
|
1497
1507
|
};
|
|
1498
1508
|
|
|
1499
1509
|
/*
|
|
@@ -2519,14 +2529,11 @@ const HLJS = function(hljs) {
|
|
|
2519
2529
|
// export an "instance" of the highlighter
|
|
2520
2530
|
var highlight$1 = HLJS({});
|
|
2521
2531
|
|
|
2522
|
-
var core
|
|
2532
|
+
var core = highlight$1;
|
|
2523
2533
|
|
|
2524
|
-
|
|
2525
|
-
var module = { exports: {} };
|
|
2526
|
-
return fn(module, module.exports), module.exports;
|
|
2527
|
-
}
|
|
2534
|
+
var format = {exports: {}};
|
|
2528
2535
|
|
|
2529
|
-
|
|
2536
|
+
(function (module) {
|
|
2530
2537
|
(function() {
|
|
2531
2538
|
|
|
2532
2539
|
//// Export the API
|
|
@@ -2638,20 +2645,22 @@ var format = createCommonjsModule(function (module) {
|
|
|
2638
2645
|
}
|
|
2639
2646
|
|
|
2640
2647
|
}());
|
|
2641
|
-
});
|
|
2648
|
+
}(format));
|
|
2649
|
+
|
|
2650
|
+
var formatter = format.exports;
|
|
2642
2651
|
|
|
2643
|
-
var fault = create(Error);
|
|
2652
|
+
var fault$1 = create(Error);
|
|
2644
2653
|
|
|
2645
|
-
var fault_1 = fault;
|
|
2654
|
+
var fault_1 = fault$1;
|
|
2646
2655
|
|
|
2647
|
-
fault.eval = create(EvalError);
|
|
2648
|
-
fault.range = create(RangeError);
|
|
2649
|
-
fault.reference = create(ReferenceError);
|
|
2650
|
-
fault.syntax = create(SyntaxError);
|
|
2651
|
-
fault.type = create(TypeError);
|
|
2652
|
-
fault.uri = create(URIError);
|
|
2656
|
+
fault$1.eval = create(EvalError);
|
|
2657
|
+
fault$1.range = create(RangeError);
|
|
2658
|
+
fault$1.reference = create(ReferenceError);
|
|
2659
|
+
fault$1.syntax = create(SyntaxError);
|
|
2660
|
+
fault$1.type = create(TypeError);
|
|
2661
|
+
fault$1.uri = create(URIError);
|
|
2653
2662
|
|
|
2654
|
-
fault.create = create;
|
|
2663
|
+
fault$1.create = create;
|
|
2655
2664
|
|
|
2656
2665
|
// Create a new `EConstructor`, with the formatted `format` as a first argument.
|
|
2657
2666
|
function create(EConstructor) {
|
|
@@ -2659,20 +2668,23 @@ function create(EConstructor) {
|
|
|
2659
2668
|
|
|
2660
2669
|
return FormattedError
|
|
2661
2670
|
|
|
2662
|
-
function FormattedError(format
|
|
2663
|
-
if (format
|
|
2664
|
-
format
|
|
2671
|
+
function FormattedError(format) {
|
|
2672
|
+
if (format) {
|
|
2673
|
+
format = formatter.apply(null, arguments);
|
|
2665
2674
|
}
|
|
2666
2675
|
|
|
2667
|
-
return new EConstructor(format
|
|
2676
|
+
return new EConstructor(format)
|
|
2668
2677
|
}
|
|
2669
2678
|
}
|
|
2670
2679
|
|
|
2671
|
-
var
|
|
2672
|
-
var
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2680
|
+
var high = core;
|
|
2681
|
+
var fault = fault_1;
|
|
2682
|
+
|
|
2683
|
+
core$1.highlight = highlight;
|
|
2684
|
+
core$1.highlightAuto = highlightAuto;
|
|
2685
|
+
core$1.registerLanguage = registerLanguage;
|
|
2686
|
+
core$1.listLanguages = listLanguages;
|
|
2687
|
+
core$1.registerAlias = registerAlias;
|
|
2676
2688
|
|
|
2677
2689
|
Emitter.prototype.addText = text;
|
|
2678
2690
|
Emitter.prototype.addKeyword = addKeyword;
|
|
@@ -2687,32 +2699,32 @@ var defaultPrefix = 'hljs-';
|
|
|
2687
2699
|
|
|
2688
2700
|
// Highlighting `value` in the language `name`.
|
|
2689
2701
|
function highlight(name, value, options) {
|
|
2690
|
-
var before =
|
|
2702
|
+
var before = high.configure({});
|
|
2691
2703
|
var settings = options || {};
|
|
2692
2704
|
var prefix = settings.prefix;
|
|
2693
2705
|
var result;
|
|
2694
2706
|
|
|
2695
2707
|
if (typeof name !== 'string') {
|
|
2696
|
-
throw
|
|
2708
|
+
throw fault('Expected `string` for name, got `%s`', name)
|
|
2697
2709
|
}
|
|
2698
2710
|
|
|
2699
|
-
if (!
|
|
2700
|
-
throw
|
|
2711
|
+
if (!high.getLanguage(name)) {
|
|
2712
|
+
throw fault('Unknown language: `%s` is not registered', name)
|
|
2701
2713
|
}
|
|
2702
2714
|
|
|
2703
2715
|
if (typeof value !== 'string') {
|
|
2704
|
-
throw
|
|
2716
|
+
throw fault('Expected `string` for value, got `%s`', value)
|
|
2705
2717
|
}
|
|
2706
2718
|
|
|
2707
2719
|
if (prefix === null || prefix === undefined) {
|
|
2708
2720
|
prefix = defaultPrefix;
|
|
2709
2721
|
}
|
|
2710
2722
|
|
|
2711
|
-
|
|
2723
|
+
high.configure({__emitter: Emitter, classPrefix: prefix});
|
|
2712
2724
|
|
|
2713
|
-
result =
|
|
2725
|
+
result = high.highlight(value, {language: name, ignoreIllegals: true});
|
|
2714
2726
|
|
|
2715
|
-
|
|
2727
|
+
high.configure(before || {});
|
|
2716
2728
|
|
|
2717
2729
|
/* istanbul ignore if - Highlight.js seems to use this (currently) for broken
|
|
2718
2730
|
* grammars, so let’s keep it in there just to be sure. */
|
|
@@ -2729,7 +2741,7 @@ function highlight(name, value, options) {
|
|
|
2729
2741
|
|
|
2730
2742
|
function highlightAuto(value, options) {
|
|
2731
2743
|
var settings = options || {};
|
|
2732
|
-
var subset = settings.subset ||
|
|
2744
|
+
var subset = settings.subset || high.listLanguages();
|
|
2733
2745
|
settings.prefix;
|
|
2734
2746
|
var length = subset.length;
|
|
2735
2747
|
var index = -1;
|
|
@@ -2739,7 +2751,7 @@ function highlightAuto(value, options) {
|
|
|
2739
2751
|
var name;
|
|
2740
2752
|
|
|
2741
2753
|
if (typeof value !== 'string') {
|
|
2742
|
-
throw
|
|
2754
|
+
throw fault('Expected `string` for value, got `%s`', value)
|
|
2743
2755
|
}
|
|
2744
2756
|
|
|
2745
2757
|
secondBest = {relevance: 0, language: null, value: []};
|
|
@@ -2748,7 +2760,7 @@ function highlightAuto(value, options) {
|
|
|
2748
2760
|
while (++index < length) {
|
|
2749
2761
|
name = subset[index];
|
|
2750
2762
|
|
|
2751
|
-
if (!
|
|
2763
|
+
if (!high.getLanguage(name)) {
|
|
2752
2764
|
continue
|
|
2753
2765
|
}
|
|
2754
2766
|
|
|
@@ -2774,12 +2786,12 @@ function highlightAuto(value, options) {
|
|
|
2774
2786
|
|
|
2775
2787
|
// Register a language.
|
|
2776
2788
|
function registerLanguage(name, syntax) {
|
|
2777
|
-
|
|
2789
|
+
high.registerLanguage(name, syntax);
|
|
2778
2790
|
}
|
|
2779
2791
|
|
|
2780
2792
|
// Get a list of all registered languages.
|
|
2781
2793
|
function listLanguages() {
|
|
2782
|
-
return
|
|
2794
|
+
return high.listLanguages()
|
|
2783
2795
|
}
|
|
2784
2796
|
|
|
2785
2797
|
// Register more aliases for an already registered language.
|
|
@@ -2793,7 +2805,7 @@ function registerAlias(name, alias) {
|
|
|
2793
2805
|
}
|
|
2794
2806
|
|
|
2795
2807
|
for (key in map) {
|
|
2796
|
-
|
|
2808
|
+
high.registerAliases(map[key], {languageName: key});
|
|
2797
2809
|
}
|
|
2798
2810
|
}
|
|
2799
2811
|
|
|
@@ -2867,14 +2879,6 @@ function toHtmlNoop() {
|
|
|
2867
2879
|
|
|
2868
2880
|
function noop() {}
|
|
2869
2881
|
|
|
2870
|
-
var core = {
|
|
2871
|
-
highlight: highlight_1,
|
|
2872
|
-
highlightAuto: highlightAuto_1,
|
|
2873
|
-
registerLanguage: registerLanguage_1,
|
|
2874
|
-
listLanguages: listLanguages_1,
|
|
2875
|
-
registerAlias: registerAlias_1
|
|
2876
|
-
};
|
|
2877
|
-
|
|
2878
2882
|
function parseNodes(nodes, className = []) {
|
|
2879
2883
|
return nodes
|
|
2880
2884
|
.map(node => {
|
|
@@ -2894,18 +2898,20 @@ function parseNodes(nodes, className = []) {
|
|
|
2894
2898
|
})
|
|
2895
2899
|
.flat();
|
|
2896
2900
|
}
|
|
2897
|
-
function
|
|
2901
|
+
function getHighlightNodes(result) {
|
|
2902
|
+
// `.value` for lowlight v1, `.children` for lowlight v2
|
|
2903
|
+
return result.value || result.children || [];
|
|
2904
|
+
}
|
|
2905
|
+
function getDecorations({ doc, name, lowlight, defaultLanguage, }) {
|
|
2898
2906
|
const decorations = [];
|
|
2899
2907
|
core$2.findChildren(doc, node => node.type.name === name)
|
|
2900
2908
|
.forEach(block => {
|
|
2901
2909
|
let from = block.pos + 1;
|
|
2902
|
-
const
|
|
2903
|
-
// TODO: add missing type for `listLanguages`
|
|
2904
|
-
// @ts-ignore
|
|
2910
|
+
const language = block.node.attrs.language || defaultLanguage;
|
|
2905
2911
|
const languages = lowlight.listLanguages();
|
|
2906
2912
|
const nodes = language && languages.includes(language)
|
|
2907
|
-
? lowlight.highlight(language, block.node.textContent)
|
|
2908
|
-
: lowlight.highlightAuto(block.node.textContent)
|
|
2913
|
+
? getHighlightNodes(lowlight.highlight(language, block.node.textContent))
|
|
2914
|
+
: getHighlightNodes(lowlight.highlightAuto(block.node.textContent));
|
|
2909
2915
|
parseNodes(nodes).forEach(node => {
|
|
2910
2916
|
const to = from + node.text.length;
|
|
2911
2917
|
if (node.classes.length) {
|
|
@@ -2919,11 +2925,16 @@ function getDecorations({ doc, name, lowlight }) {
|
|
|
2919
2925
|
});
|
|
2920
2926
|
return prosemirrorView.DecorationSet.create(doc, decorations);
|
|
2921
2927
|
}
|
|
2922
|
-
function LowlightPlugin({ name, lowlight }) {
|
|
2928
|
+
function LowlightPlugin({ name, lowlight, defaultLanguage }) {
|
|
2923
2929
|
return new prosemirrorState.Plugin({
|
|
2924
2930
|
key: new prosemirrorState.PluginKey('lowlight'),
|
|
2925
2931
|
state: {
|
|
2926
|
-
init: (_, { doc }) => getDecorations({
|
|
2932
|
+
init: (_, { doc }) => getDecorations({
|
|
2933
|
+
doc,
|
|
2934
|
+
name,
|
|
2935
|
+
lowlight,
|
|
2936
|
+
defaultLanguage,
|
|
2937
|
+
}),
|
|
2927
2938
|
apply: (transaction, decorationSet, oldState, newState) => {
|
|
2928
2939
|
const oldNodeName = oldState.selection.$head.parent.type.name;
|
|
2929
2940
|
const newNodeName = newState.selection.$head.parent.type.name;
|
|
@@ -2951,7 +2962,12 @@ function LowlightPlugin({ name, lowlight }) {
|
|
|
2951
2962
|
&& node.pos + node.node.nodeSize <= step.to;
|
|
2952
2963
|
});
|
|
2953
2964
|
}))) {
|
|
2954
|
-
return getDecorations({
|
|
2965
|
+
return getDecorations({
|
|
2966
|
+
doc: transaction.doc,
|
|
2967
|
+
name,
|
|
2968
|
+
lowlight,
|
|
2969
|
+
defaultLanguage,
|
|
2970
|
+
});
|
|
2955
2971
|
}
|
|
2956
2972
|
return decorationSet.map(transaction.mapping, transaction.doc);
|
|
2957
2973
|
},
|
|
@@ -2964,23 +2980,28 @@ function LowlightPlugin({ name, lowlight }) {
|
|
|
2964
2980
|
});
|
|
2965
2981
|
}
|
|
2966
2982
|
|
|
2967
|
-
const CodeBlockLowlight = CodeBlock__default[
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2983
|
+
const CodeBlockLowlight = CodeBlock__default["default"].extend({
|
|
2984
|
+
addOptions() {
|
|
2985
|
+
var _a;
|
|
2986
|
+
return {
|
|
2987
|
+
...(_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this),
|
|
2988
|
+
lowlight: core$1,
|
|
2989
|
+
defaultLanguage: null,
|
|
2990
|
+
};
|
|
2971
2991
|
},
|
|
2972
2992
|
addProseMirrorPlugins() {
|
|
2993
|
+
var _a;
|
|
2973
2994
|
return [
|
|
2974
|
-
|
|
2975
|
-
// ...this.parentConfig.addProseMirrorPlugins?.() || [],
|
|
2995
|
+
...((_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this)) || [],
|
|
2976
2996
|
LowlightPlugin({
|
|
2977
|
-
name:
|
|
2997
|
+
name: this.name,
|
|
2978
2998
|
lowlight: this.options.lowlight,
|
|
2999
|
+
defaultLanguage: this.options.defaultLanguage,
|
|
2979
3000
|
}),
|
|
2980
3001
|
];
|
|
2981
3002
|
},
|
|
2982
3003
|
});
|
|
2983
3004
|
|
|
2984
3005
|
exports.CodeBlockLowlight = CodeBlockLowlight;
|
|
2985
|
-
exports
|
|
3006
|
+
exports["default"] = CodeBlockLowlight;
|
|
2986
3007
|
//# sourceMappingURL=tiptap-extension-code-block-lowlight.cjs.js.map
|