md-editor-v3 5.0.1 → 5.0.2

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.
@@ -376,44 +376,40 @@ const math_block = (state, start, end, silent) => {
376
376
  let pos = state.bMarks[start] + state.tShift[start];
377
377
  let max = state.eMarks[start];
378
378
  for (const delim of delimiters) {
379
- if (pos + delim.open.length > max) {
380
- continue;
381
- }
382
- if (state.src.slice(pos, pos + delim.open.length) !== delim.open) {
383
- continue;
384
- }
385
- pos += delim.open.length;
386
- firstLine = state.src.slice(pos, max);
387
- if (silent) {
388
- return true;
389
- }
390
- if (firstLine.trim().slice(-delim.close.length) === delim.close) {
391
- firstLine = firstLine.trim().slice(0, -delim.close.length);
392
- found = true;
393
- }
394
- for (next = start; !found; ) {
395
- next++;
396
- if (next >= end) {
397
- break;
398
- }
399
- pos = state.bMarks[next] + state.tShift[next];
400
- max = state.eMarks[next];
401
- if (pos < max && state.tShift[next] < state.blkIndent) {
402
- break;
379
+ if (state.src.slice(pos, pos + delim.open.length) === delim.open && state.src.slice(max - delim.close.length, max) === delim.close) {
380
+ pos += delim.open.length;
381
+ firstLine = state.src.slice(pos, max);
382
+ if (silent) {
383
+ return true;
403
384
  }
404
- if (state.src.slice(pos, max).trim().slice(-delim.close.length) === delim.close) {
405
- lastPos = state.src.slice(0, max).lastIndexOf(delim.close);
406
- lastLine = state.src.slice(pos, lastPos);
385
+ if (firstLine.trim().slice(-delim.close.length) === delim.close) {
386
+ firstLine = firstLine.trim().slice(0, -delim.close.length);
407
387
  found = true;
408
388
  }
389
+ for (next = start; !found; ) {
390
+ next++;
391
+ if (next >= end) {
392
+ break;
393
+ }
394
+ pos = state.bMarks[next] + state.tShift[next];
395
+ max = state.eMarks[next];
396
+ if (pos < max && state.tShift[next] < state.blkIndent) {
397
+ break;
398
+ }
399
+ if (state.src.slice(pos, max).trim().slice(-delim.close.length) === delim.close) {
400
+ lastPos = state.src.slice(0, max).lastIndexOf(delim.close);
401
+ lastLine = state.src.slice(pos, lastPos);
402
+ found = true;
403
+ }
404
+ }
405
+ state.line = next + 1;
406
+ const token = state.push("math_block", "math", 0);
407
+ token.block = true;
408
+ token.content = (firstLine && firstLine.trim() ? firstLine + "\n" : "") + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : "");
409
+ token.map = [start, state.line];
410
+ token.markup = delim.open;
411
+ return true;
409
412
  }
410
- state.line = next + 1;
411
- const token = state.push("math_block", "math", 0);
412
- token.block = true;
413
- token.content = (firstLine && firstLine.trim() ? firstLine + "\n" : "") + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : "");
414
- token.map = [start, state.line];
415
- token.markup = delim.open;
416
- return true;
417
413
  }
418
414
  return false;
419
415
  };
@@ -973,7 +969,6 @@ const useMarkdownIt = (props, previewOnly) => {
973
969
  });
974
970
  });
975
971
  };
976
- vue.onMounted(updatedTodo);
977
972
  const markHtml = () => {
978
973
  headsRef.value = [];
979
974
  html.value = props.sanitize(md.render(props.modelValue));
@@ -982,10 +977,15 @@ const useMarkdownIt = (props, previewOnly) => {
982
977
  const needReRender = vue.computed(() => {
983
978
  return (props.noKatex || katexRef.value) && (props.noHighlight || hljsRef.value);
984
979
  });
985
- vue.watch(
986
- [vue.toRef(props, "modelValue"), needReRender, reRenderRef, languageRef],
987
- util.debounce(markHtml, previewOnly ? 0 : editorConfig.renderDelay)
988
- );
980
+ let timer = -1;
981
+ vue.watch([vue.toRef(props, "modelValue"), needReRender, reRenderRef, languageRef], () => {
982
+ timer = window.setTimeout(
983
+ () => {
984
+ markHtml();
985
+ },
986
+ previewOnly ? 0 : editorConfig.renderDelay
987
+ );
988
+ });
989
989
  vue.watch(
990
990
  () => props.setting.preview,
991
991
  () => {
@@ -1001,6 +1001,7 @@ const useMarkdownIt = (props, previewOnly) => {
1001
1001
  }
1002
1002
  }
1003
1003
  );
1004
+ vue.onMounted(updatedTodo);
1004
1005
  vue.onMounted(() => {
1005
1006
  eventName.bus.on(editorId, {
1006
1007
  name: eventName.PUSH_CATALOG,
@@ -1016,6 +1017,9 @@ const useMarkdownIt = (props, previewOnly) => {
1016
1017
  }
1017
1018
  });
1018
1019
  });
1020
+ vue.onBeforeUnmount(() => {
1021
+ clearTimeout(timer);
1022
+ });
1019
1023
  return { html, key };
1020
1024
  };
1021
1025
  const template = {
@@ -375,44 +375,40 @@ const math_block = (state, start, end, silent) => {
375
375
  let pos = state.bMarks[start] + state.tShift[start];
376
376
  let max = state.eMarks[start];
377
377
  for (const delim of delimiters) {
378
- if (pos + delim.open.length > max) {
379
- continue;
380
- }
381
- if (state.src.slice(pos, pos + delim.open.length) !== delim.open) {
382
- continue;
383
- }
384
- pos += delim.open.length;
385
- firstLine = state.src.slice(pos, max);
386
- if (silent) {
387
- return true;
388
- }
389
- if (firstLine.trim().slice(-delim.close.length) === delim.close) {
390
- firstLine = firstLine.trim().slice(0, -delim.close.length);
391
- found = true;
392
- }
393
- for (next = start; !found; ) {
394
- next++;
395
- if (next >= end) {
396
- break;
397
- }
398
- pos = state.bMarks[next] + state.tShift[next];
399
- max = state.eMarks[next];
400
- if (pos < max && state.tShift[next] < state.blkIndent) {
401
- break;
378
+ if (state.src.slice(pos, pos + delim.open.length) === delim.open && state.src.slice(max - delim.close.length, max) === delim.close) {
379
+ pos += delim.open.length;
380
+ firstLine = state.src.slice(pos, max);
381
+ if (silent) {
382
+ return true;
402
383
  }
403
- if (state.src.slice(pos, max).trim().slice(-delim.close.length) === delim.close) {
404
- lastPos = state.src.slice(0, max).lastIndexOf(delim.close);
405
- lastLine = state.src.slice(pos, lastPos);
384
+ if (firstLine.trim().slice(-delim.close.length) === delim.close) {
385
+ firstLine = firstLine.trim().slice(0, -delim.close.length);
406
386
  found = true;
407
387
  }
388
+ for (next = start; !found; ) {
389
+ next++;
390
+ if (next >= end) {
391
+ break;
392
+ }
393
+ pos = state.bMarks[next] + state.tShift[next];
394
+ max = state.eMarks[next];
395
+ if (pos < max && state.tShift[next] < state.blkIndent) {
396
+ break;
397
+ }
398
+ if (state.src.slice(pos, max).trim().slice(-delim.close.length) === delim.close) {
399
+ lastPos = state.src.slice(0, max).lastIndexOf(delim.close);
400
+ lastLine = state.src.slice(pos, lastPos);
401
+ found = true;
402
+ }
403
+ }
404
+ state.line = next + 1;
405
+ const token = state.push("math_block", "math", 0);
406
+ token.block = true;
407
+ token.content = (firstLine && firstLine.trim() ? firstLine + "\n" : "") + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : "");
408
+ token.map = [start, state.line];
409
+ token.markup = delim.open;
410
+ return true;
408
411
  }
409
- state.line = next + 1;
410
- const token = state.push("math_block", "math", 0);
411
- token.block = true;
412
- token.content = (firstLine && firstLine.trim() ? firstLine + "\n" : "") + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : "");
413
- token.map = [start, state.line];
414
- token.markup = delim.open;
415
- return true;
416
412
  }
417
413
  return false;
418
414
  };
@@ -972,7 +968,6 @@ const useMarkdownIt = (props, previewOnly) => {
972
968
  });
973
969
  });
974
970
  };
975
- onMounted(updatedTodo);
976
971
  const markHtml = () => {
977
972
  headsRef.value = [];
978
973
  html.value = props.sanitize(md.render(props.modelValue));
@@ -981,10 +976,15 @@ const useMarkdownIt = (props, previewOnly) => {
981
976
  const needReRender = computed(() => {
982
977
  return (props.noKatex || katexRef.value) && (props.noHighlight || hljsRef.value);
983
978
  });
984
- watch(
985
- [toRef(props, "modelValue"), needReRender, reRenderRef, languageRef],
986
- debounce(markHtml, previewOnly ? 0 : editorConfig.renderDelay)
987
- );
979
+ let timer = -1;
980
+ watch([toRef(props, "modelValue"), needReRender, reRenderRef, languageRef], () => {
981
+ timer = window.setTimeout(
982
+ () => {
983
+ markHtml();
984
+ },
985
+ previewOnly ? 0 : editorConfig.renderDelay
986
+ );
987
+ });
988
988
  watch(
989
989
  () => props.setting.preview,
990
990
  () => {
@@ -1000,6 +1000,7 @@ const useMarkdownIt = (props, previewOnly) => {
1000
1000
  }
1001
1001
  }
1002
1002
  );
1003
+ onMounted(updatedTodo);
1003
1004
  onMounted(() => {
1004
1005
  bus.on(editorId, {
1005
1006
  name: PUSH_CATALOG,
@@ -1015,6 +1016,9 @@ const useMarkdownIt = (props, previewOnly) => {
1015
1016
  }
1016
1017
  });
1017
1018
  });
1019
+ onBeforeUnmount(() => {
1020
+ clearTimeout(timer);
1021
+ });
1018
1022
  return { html, key };
1019
1023
  };
1020
1024
  const template = {