@tiptap/extension-code-block-lowlight 2.0.0-beta.50 → 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.
@@ -2899,12 +2899,13 @@
2899
2899
  // `.value` for lowlight v1, `.children` for lowlight v2
2900
2900
  return result.value || result.children || [];
2901
2901
  }
2902
- function getDecorations({ doc, name, lowlight }) {
2902
+ function getDecorations({ doc, name, lowlight, defaultLanguage, }) {
2903
2903
  const decorations = [];
2904
2904
  core$2.findChildren(doc, node => node.type.name === name)
2905
2905
  .forEach(block => {
2906
2906
  let from = block.pos + 1;
2907
- const { language } = block.node.attrs;
2907
+ const language = block.node.attrs.language || defaultLanguage;
2908
+ console.log({ language, defaultLanguage });
2908
2909
  const languages = lowlight.listLanguages();
2909
2910
  const nodes = language && languages.includes(language)
2910
2911
  ? getHighlightNodes(lowlight.highlight(language, block.node.textContent))
@@ -2922,11 +2923,16 @@
2922
2923
  });
2923
2924
  return prosemirrorView.DecorationSet.create(doc, decorations);
2924
2925
  }
2925
- function LowlightPlugin({ name, lowlight }) {
2926
+ function LowlightPlugin({ name, lowlight, defaultLanguage }) {
2926
2927
  return new prosemirrorState.Plugin({
2927
2928
  key: new prosemirrorState.PluginKey('lowlight'),
2928
2929
  state: {
2929
- init: (_, { doc }) => getDecorations({ doc, name, lowlight }),
2930
+ init: (_, { doc }) => getDecorations({
2931
+ doc,
2932
+ name,
2933
+ lowlight,
2934
+ defaultLanguage,
2935
+ }),
2930
2936
  apply: (transaction, decorationSet, oldState, newState) => {
2931
2937
  const oldNodeName = oldState.selection.$head.parent.type.name;
2932
2938
  const newNodeName = newState.selection.$head.parent.type.name;
@@ -2954,7 +2960,12 @@
2954
2960
  && node.pos + node.node.nodeSize <= step.to;
2955
2961
  });
2956
2962
  }))) {
2957
- return getDecorations({ doc: transaction.doc, name, lowlight });
2963
+ return getDecorations({
2964
+ doc: transaction.doc,
2965
+ name,
2966
+ lowlight,
2967
+ defaultLanguage,
2968
+ });
2958
2969
  }
2959
2970
  return decorationSet.map(transaction.mapping, transaction.doc);
2960
2971
  },
@@ -2973,6 +2984,7 @@
2973
2984
  return {
2974
2985
  ...(_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this),
2975
2986
  lowlight: core$1,
2987
+ defaultLanguage: null,
2976
2988
  };
2977
2989
  },
2978
2990
  addProseMirrorPlugins() {
@@ -2982,6 +2994,7 @@
2982
2994
  LowlightPlugin({
2983
2995
  name: this.name,
2984
2996
  lowlight: this.options.lowlight,
2997
+ defaultLanguage: this.options.defaultLanguage,
2985
2998
  }),
2986
2999
  ];
2987
3000
  },