@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.
@@ -2894,12 +2894,13 @@ function getHighlightNodes(result) {
2894
2894
  // `.value` for lowlight v1, `.children` for lowlight v2
2895
2895
  return result.value || result.children || [];
2896
2896
  }
2897
- function getDecorations({ doc, name, lowlight }) {
2897
+ function getDecorations({ doc, name, lowlight, defaultLanguage, }) {
2898
2898
  const decorations = [];
2899
2899
  findChildren(doc, node => node.type.name === name)
2900
2900
  .forEach(block => {
2901
2901
  let from = block.pos + 1;
2902
- const { language } = block.node.attrs;
2902
+ const language = block.node.attrs.language || defaultLanguage;
2903
+ console.log({ language, defaultLanguage });
2903
2904
  const languages = lowlight.listLanguages();
2904
2905
  const nodes = language && languages.includes(language)
2905
2906
  ? getHighlightNodes(lowlight.highlight(language, block.node.textContent))
@@ -2917,11 +2918,16 @@ function getDecorations({ doc, name, lowlight }) {
2917
2918
  });
2918
2919
  return DecorationSet.create(doc, decorations);
2919
2920
  }
2920
- function LowlightPlugin({ name, lowlight }) {
2921
+ function LowlightPlugin({ name, lowlight, defaultLanguage }) {
2921
2922
  return new Plugin({
2922
2923
  key: new PluginKey('lowlight'),
2923
2924
  state: {
2924
- init: (_, { doc }) => getDecorations({ doc, name, lowlight }),
2925
+ init: (_, { doc }) => getDecorations({
2926
+ doc,
2927
+ name,
2928
+ lowlight,
2929
+ defaultLanguage,
2930
+ }),
2925
2931
  apply: (transaction, decorationSet, oldState, newState) => {
2926
2932
  const oldNodeName = oldState.selection.$head.parent.type.name;
2927
2933
  const newNodeName = newState.selection.$head.parent.type.name;
@@ -2949,7 +2955,12 @@ function LowlightPlugin({ name, lowlight }) {
2949
2955
  && node.pos + node.node.nodeSize <= step.to;
2950
2956
  });
2951
2957
  }))) {
2952
- return getDecorations({ doc: transaction.doc, name, lowlight });
2958
+ return getDecorations({
2959
+ doc: transaction.doc,
2960
+ name,
2961
+ lowlight,
2962
+ defaultLanguage,
2963
+ });
2953
2964
  }
2954
2965
  return decorationSet.map(transaction.mapping, transaction.doc);
2955
2966
  },
@@ -2963,9 +2974,13 @@ function LowlightPlugin({ name, lowlight }) {
2963
2974
  }
2964
2975
 
2965
2976
  const CodeBlockLowlight = CodeBlock.extend({
2966
- defaultOptions: {
2967
- ...CodeBlock.options,
2968
- lowlight: core$1,
2977
+ addOptions() {
2978
+ var _a;
2979
+ return {
2980
+ ...(_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this),
2981
+ lowlight: core$1,
2982
+ defaultLanguage: null,
2983
+ };
2969
2984
  },
2970
2985
  addProseMirrorPlugins() {
2971
2986
  var _a;
@@ -2974,6 +2989,7 @@ const CodeBlockLowlight = CodeBlock.extend({
2974
2989
  LowlightPlugin({
2975
2990
  name: this.name,
2976
2991
  lowlight: this.options.lowlight,
2992
+ defaultLanguage: this.options.defaultLanguage,
2977
2993
  }),
2978
2994
  ];
2979
2995
  },