@tiptap/extension-code-block-lowlight 2.0.0-beta.49 → 2.0.0-beta.53

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.
@@ -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
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>;
@@ -2902,12 +2902,13 @@ function getHighlightNodes(result) {
2902
2902
  // `.value` for lowlight v1, `.children` for lowlight v2
2903
2903
  return result.value || result.children || [];
2904
2904
  }
2905
- function getDecorations({ doc, name, lowlight }) {
2905
+ function getDecorations({ doc, name, lowlight, defaultLanguage, }) {
2906
2906
  const decorations = [];
2907
2907
  core$2.findChildren(doc, node => node.type.name === name)
2908
2908
  .forEach(block => {
2909
2909
  let from = block.pos + 1;
2910
- const { language } = block.node.attrs;
2910
+ const language = block.node.attrs.language || defaultLanguage;
2911
+ console.log({ language, defaultLanguage });
2911
2912
  const languages = lowlight.listLanguages();
2912
2913
  const nodes = language && languages.includes(language)
2913
2914
  ? getHighlightNodes(lowlight.highlight(language, block.node.textContent))
@@ -2925,11 +2926,16 @@ function getDecorations({ doc, name, lowlight }) {
2925
2926
  });
2926
2927
  return prosemirrorView.DecorationSet.create(doc, decorations);
2927
2928
  }
2928
- function LowlightPlugin({ name, lowlight }) {
2929
+ function LowlightPlugin({ name, lowlight, defaultLanguage }) {
2929
2930
  return new prosemirrorState.Plugin({
2930
2931
  key: new prosemirrorState.PluginKey('lowlight'),
2931
2932
  state: {
2932
- init: (_, { doc }) => getDecorations({ doc, name, lowlight }),
2933
+ init: (_, { doc }) => getDecorations({
2934
+ doc,
2935
+ name,
2936
+ lowlight,
2937
+ defaultLanguage,
2938
+ }),
2933
2939
  apply: (transaction, decorationSet, oldState, newState) => {
2934
2940
  const oldNodeName = oldState.selection.$head.parent.type.name;
2935
2941
  const newNodeName = newState.selection.$head.parent.type.name;
@@ -2957,7 +2963,12 @@ function LowlightPlugin({ name, lowlight }) {
2957
2963
  && node.pos + node.node.nodeSize <= step.to;
2958
2964
  });
2959
2965
  }))) {
2960
- return getDecorations({ doc: transaction.doc, name, lowlight });
2966
+ return getDecorations({
2967
+ doc: transaction.doc,
2968
+ name,
2969
+ lowlight,
2970
+ defaultLanguage,
2971
+ });
2961
2972
  }
2962
2973
  return decorationSet.map(transaction.mapping, transaction.doc);
2963
2974
  },
@@ -2976,6 +2987,7 @@ const CodeBlockLowlight = CodeBlock__default["default"].extend({
2976
2987
  return {
2977
2988
  ...(_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this),
2978
2989
  lowlight: core$1,
2990
+ defaultLanguage: null,
2979
2991
  };
2980
2992
  },
2981
2993
  addProseMirrorPlugins() {
@@ -2985,6 +2997,7 @@ const CodeBlockLowlight = CodeBlock__default["default"].extend({
2985
2997
  LowlightPlugin({
2986
2998
  name: this.name,
2987
2999
  lowlight: this.options.lowlight,
3000
+ defaultLanguage: this.options.defaultLanguage,
2988
3001
  }),
2989
3002
  ];
2990
3003
  },