md-editor-v3 4.15.1-0 → 4.15.1-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.
@@ -1347,7 +1347,7 @@ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
1347
1347
  startEleOffetTop = startEle.offsetTop;
1348
1348
  blockHeight = endEle.offsetTop - startEleOffetTop;
1349
1349
  }
1350
- if (endLinePosition > scrollDOM.scrollHeight - scrollDOM.clientHeight) {
1350
+ if (endLinePosition >= scrollDOM.scrollHeight - scrollDOM.clientHeight) {
1351
1351
  scale = (scrollDOM.scrollTop - startTop) / (scrollDOM.scrollHeight - scrollDOM.clientHeight - startTop);
1352
1352
  startEleOffetTop = startEle.offsetTop;
1353
1353
  blockHeight = cEle.scrollHeight - cEle.clientHeight - startEleOffetTop + 10;
@@ -12,6 +12,7 @@ const TaskListPlugin = require("markdown-it-task-lists");
12
12
  const XSSPlugin = require("markdown-it-xss");
13
13
  const index = require("./index4.cjs");
14
14
  const lruCache = require("lru-cache");
15
+ const markdownIt = require("~/utils/markdown-it");
15
16
  const userZoom = (props, html) => {
16
17
  const editorId = vue.inject("editorId");
17
18
  const { noImgZoomIn } = props;
@@ -376,38 +377,42 @@ const math_block = (state, start, end, silent) => {
376
377
  token.markup = "$$";
377
378
  return true;
378
379
  };
379
- const KatexPlugin = (md, options) => {
380
- const katexInline = (str) => {
381
- if (options.katexRef.value) {
382
- const html = options.katexRef.value.renderToString(str, {
380
+ const KatexPlugin = (md, { katexRef }) => {
381
+ const katexInline = (tokens, idx, options, env, slf) => {
382
+ const token = tokens[idx];
383
+ const tmpToken = {
384
+ attrs: markdownIt.mergeAttrs(token, [["class", `${config.prefix}-katex-inline`]])
385
+ };
386
+ if (katexRef.value) {
387
+ const html = katexRef.value.renderToString(token.content, {
383
388
  throwOnError: false
384
389
  });
385
- return `<span class="${config.prefix}-katex-inline" data-processed>${html}</span>`;
390
+ return `<span ${slf.renderAttrs(tmpToken)} data-processed>${html}</span>`;
386
391
  } else {
387
- return `<span class="${config.prefix}-katex-inline">${str}</span>`;
392
+ return `<span ${slf.renderAttrs(tmpToken)}>${token.content}</span>`;
388
393
  }
389
394
  };
390
- const katexBlock = (str, lineNum) => {
391
- if (options.katexRef.value) {
392
- const html = options.katexRef.value.renderToString(str, {
395
+ const katexBlock = (tokens, idx, options, env, slf) => {
396
+ const token = tokens[idx];
397
+ const tmpToken = {
398
+ attrs: markdownIt.mergeAttrs(token, [["class", `${config.prefix}-katex-block`]])
399
+ };
400
+ if (katexRef.value) {
401
+ const html = katexRef.value.renderToString(token.content, {
393
402
  throwOnError: false,
394
403
  displayMode: true
395
404
  });
396
- return `<p class="${config.prefix}-katex-block" data-line=${lineNum} data-processed>${html}</p>`;
405
+ return `<p ${slf.renderAttrs(tmpToken)} data-processed>${html}</p>`;
397
406
  } else {
398
- return `<p class="${config.prefix}-katex-block" data-line=${lineNum}>${str}</p>`;
407
+ return `<p ${slf.renderAttrs(tmpToken)}>${token.content}</p>`;
399
408
  }
400
409
  };
401
410
  md.inline.ruler.after("escape", "math_inline", math_inline);
402
411
  md.block.ruler.after("blockquote", "math_block", math_block, {
403
412
  alt: ["paragraph", "reference", "blockquote", "list"]
404
413
  });
405
- md.renderer.rules.math_inline = (tokens, idx) => {
406
- return katexInline(tokens[idx].content);
407
- };
408
- md.renderer.rules.math_block = (tokens, idx) => {
409
- return katexBlock(tokens[idx].content, tokens[idx].map[0]) + "\n";
410
- };
414
+ md.renderer.rules.math_inline = katexInline;
415
+ md.renderer.rules.math_block = katexBlock;
411
416
  };
412
417
  const KatexPlugin$1 = KatexPlugin;
413
418
  const AdmonitionPlugin = (md, options) => {
@@ -421,7 +426,6 @@ const AdmonitionPlugin = (md, options) => {
421
426
  "class",
422
427
  `${config.prefix}-admonition ${config.prefix}-admonition-${token.info}`
423
428
  ]);
424
- tokens[idx].attrSet("data-line", String(tokens[idx].map[0]));
425
429
  } else if (token.type === "admonition_title_open") {
426
430
  tokens[idx].attrPush(["class", `${config.prefix}-admonition-title`]);
427
431
  }
@@ -545,7 +549,6 @@ const HeadingPlugin = (md, options) => {
545
549
  level
546
550
  });
547
551
  if (token.map && token.level === 0) {
548
- token.attrSet("data-line", String(token.map[0]));
549
552
  token.attrSet(
550
553
  "id",
551
554
  options.mdHeadingId(text, level, options.headsRef.value.length)
@@ -560,17 +563,22 @@ const HeadingPlugin = (md, options) => {
560
563
  const HeadingPlugin$1 = HeadingPlugin;
561
564
  const codetabs = (md, _opts) => {
562
565
  const defaultRender = md.renderer.rules.fence, unescapeAll = md.utils.unescapeAll, re = /\[(\w*)(?::([\w ]*))?\]/;
563
- function getInfo(token) {
566
+ const getInfo = (token) => {
564
567
  return token.info ? unescapeAll(token.info).trim() : "";
565
- }
566
- function getGroupAndTab(token) {
568
+ };
569
+ const getGroupAndTab = (token) => {
567
570
  const info = getInfo(token), [group = null, tab = ""] = (re.exec(info) || []).slice(1);
568
571
  return [group, tab];
569
- }
570
- function getLangName(token) {
572
+ };
573
+ const getLangName = (token) => {
571
574
  const info = getInfo(token);
572
575
  return info ? info.split(/(\s+)/g)[0] : "";
573
- }
576
+ };
577
+ const getTagType = (token) => {
578
+ const open = token.content.trim().split("\n").length < _opts.autoFoldThreshold;
579
+ const tagContainer = _opts.codeFoldable ? "details" : "div", tagHeader = _opts.codeFoldable ? "summary" : "div";
580
+ return { open, tagContainer, tagHeader };
581
+ };
574
582
  const fenceGroup = (tokens, idx, options, env, slf) => {
575
583
  var _a, _b;
576
584
  if (tokens[idx].hidden) {
@@ -578,10 +586,14 @@ const codetabs = (md, _opts) => {
578
586
  }
579
587
  const [GROUP] = getGroupAndTab(tokens[idx]);
580
588
  if (GROUP === null) {
581
- const open2 = tokens[idx].content.trim().split("\n").length < _opts.autoFoldThreshold;
582
- const tagContainer2 = _opts.codeFoldable ? "details" : "div", tagHeader2 = _opts.codeFoldable ? "summary" : "div";
589
+ const { open: open2, tagContainer: tagContainer2, tagHeader: tagHeader2 } = getTagType(tokens[idx]);
590
+ const addAttrs2 = [["class", `${config.prefix}-code`]];
591
+ open2 && addAttrs2.push(["open", ""]);
592
+ const tmpToken2 = {
593
+ attrs: markdownIt.mergeAttrs(tokens[idx], addAttrs2)
594
+ };
583
595
  const codeRendered = defaultRender(tokens, idx, options, env, slf);
584
- return `<${tagContainer2} class="${config.prefix}-code"${open2 ? " open" : ""}>
596
+ return `<${tagContainer2} ${slf.renderAttrs(tmpToken2)}>
585
597
  <${tagHeader2} class="${config.prefix}-code-head">
586
598
  <div class="${config.prefix}-code-flag">
587
599
  <span></span>
@@ -595,8 +607,12 @@ const codetabs = (md, _opts) => {
595
607
  </${tagHeader2}>${codeRendered}</${tagContainer2}>`;
596
608
  }
597
609
  let token, group, tab, checked, labels = "", pres = "", langs = "";
598
- const open = tokens[idx].content.trim().split("\n").length < _opts.autoFoldThreshold;
599
- const tagContainer = _opts.codeFoldable ? "details" : "div", tagHeader = _opts.codeFoldable ? "summary" : "div";
610
+ const { open, tagContainer, tagHeader } = getTagType(tokens[idx]);
611
+ const addAttrs = [["class", `${config.prefix}-code`]];
612
+ open && addAttrs.push(["open", ""]);
613
+ const tmpToken = {
614
+ attrs: markdownIt.mergeAttrs(tokens[idx], addAttrs)
615
+ };
600
616
  for (let i = idx; i < tokens.length; i++) {
601
617
  token = tokens[i];
602
618
  [group, tab] = getGroupAndTab(token);
@@ -616,7 +632,7 @@ const codetabs = (md, _opts) => {
616
632
  langs += `<input type="radio" name="${config.prefix}-codetab-lang-${_opts.editorId}-${idx}" class="${className}" ${checked}>
617
633
  <span class=${config.prefix}-code-lang>${getLangName(token)}</span>`;
618
634
  }
619
- return `<${tagContainer} class="${config.prefix}-code" ${open ? " open" : ""}>
635
+ return `<${tagContainer} ${slf.renderAttrs(tmpToken)}>
620
636
  <${tagHeader} class="${config.prefix}-code-head">
621
637
  <div class="${config.prefix}-code-flag">
622
638
  <ul class="${config.prefix}-codetab-label">${labels}</ul>
@@ -631,37 +647,16 @@ const codetabs = (md, _opts) => {
631
647
  };
632
648
  const CodePlugin = codetabs;
633
649
  const initLineNumber = (md) => {
634
- [
635
- "paragraph_open",
636
- "table_open",
637
- "ordered_list_open",
638
- "bullet_list_open",
639
- "blockquote_open",
640
- "hr",
641
- "html_block",
642
- "fence"
643
- ].forEach((rule) => {
644
- const backup = md.renderer.rules[rule];
645
- if (!backup) {
646
- md.renderer.rules[rule] = (tokens, idx, options, _env, self) => {
647
- let line;
648
- if (tokens[idx].map && tokens[idx].level === 0) {
649
- line = tokens[idx].map[0];
650
- tokens[idx].attrSet("data-line", String(line));
651
- }
652
- return self.renderToken(tokens, idx, options);
653
- };
654
- } else {
655
- md.renderer.rules[rule] = (tokens, idx, options, env, self) => {
656
- let line;
657
- const _htmlCode = backup(tokens, idx, options, env, self);
658
- if (tokens[idx].map && tokens[idx].level === 0 && !/^<!--/.test(_htmlCode)) {
659
- line = tokens[idx].map[0];
660
- return _htmlCode.replace(/^(<[^>]*)/, `$1 data-line="${line}"`);
650
+ md.core.ruler.push("init-line-number", (state) => {
651
+ state.tokens.forEach((token) => {
652
+ if (token.map) {
653
+ if (!token.attrs) {
654
+ token.attrs = [];
661
655
  }
662
- return _htmlCode;
663
- };
664
- }
656
+ token.attrs.push(["data-line", token.map[0].toString()]);
657
+ }
658
+ });
659
+ return true;
665
660
  });
666
661
  };
667
662
  const useMarkdownIt = (props, previewOnly) => {
@@ -1346,7 +1346,7 @@ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
1346
1346
  startEleOffetTop = startEle.offsetTop;
1347
1347
  blockHeight = endEle.offsetTop - startEleOffetTop;
1348
1348
  }
1349
- if (endLinePosition > scrollDOM.scrollHeight - scrollDOM.clientHeight) {
1349
+ if (endLinePosition >= scrollDOM.scrollHeight - scrollDOM.clientHeight) {
1350
1350
  scale = (scrollDOM.scrollTop - startTop) / (scrollDOM.scrollHeight - scrollDOM.clientHeight - startTop);
1351
1351
  startEleOffetTop = startEle.offsetTop;
1352
1352
  blockHeight = cEle.scrollHeight - cEle.clientHeight - startEleOffetTop + 10;
@@ -11,6 +11,7 @@ import TaskListPlugin from "markdown-it-task-lists";
11
11
  import XSSPlugin from "markdown-it-xss";
12
12
  import { b as generateCodeRowNumber, c as getNextId } from "./index4.mjs";
13
13
  import { LRUCache } from "lru-cache";
14
+ import { mergeAttrs } from "~/utils/markdown-it";
14
15
  const userZoom = (props, html) => {
15
16
  const editorId = inject("editorId");
16
17
  const { noImgZoomIn } = props;
@@ -375,38 +376,42 @@ const math_block = (state, start, end, silent) => {
375
376
  token.markup = "$$";
376
377
  return true;
377
378
  };
378
- const KatexPlugin = (md, options) => {
379
- const katexInline = (str) => {
380
- if (options.katexRef.value) {
381
- const html = options.katexRef.value.renderToString(str, {
379
+ const KatexPlugin = (md, { katexRef }) => {
380
+ const katexInline = (tokens, idx, options, env, slf) => {
381
+ const token = tokens[idx];
382
+ const tmpToken = {
383
+ attrs: mergeAttrs(token, [["class", `${prefix}-katex-inline`]])
384
+ };
385
+ if (katexRef.value) {
386
+ const html = katexRef.value.renderToString(token.content, {
382
387
  throwOnError: false
383
388
  });
384
- return `<span class="${prefix}-katex-inline" data-processed>${html}</span>`;
389
+ return `<span ${slf.renderAttrs(tmpToken)} data-processed>${html}</span>`;
385
390
  } else {
386
- return `<span class="${prefix}-katex-inline">${str}</span>`;
391
+ return `<span ${slf.renderAttrs(tmpToken)}>${token.content}</span>`;
387
392
  }
388
393
  };
389
- const katexBlock = (str, lineNum) => {
390
- if (options.katexRef.value) {
391
- const html = options.katexRef.value.renderToString(str, {
394
+ const katexBlock = (tokens, idx, options, env, slf) => {
395
+ const token = tokens[idx];
396
+ const tmpToken = {
397
+ attrs: mergeAttrs(token, [["class", `${prefix}-katex-block`]])
398
+ };
399
+ if (katexRef.value) {
400
+ const html = katexRef.value.renderToString(token.content, {
392
401
  throwOnError: false,
393
402
  displayMode: true
394
403
  });
395
- return `<p class="${prefix}-katex-block" data-line=${lineNum} data-processed>${html}</p>`;
404
+ return `<p ${slf.renderAttrs(tmpToken)} data-processed>${html}</p>`;
396
405
  } else {
397
- return `<p class="${prefix}-katex-block" data-line=${lineNum}>${str}</p>`;
406
+ return `<p ${slf.renderAttrs(tmpToken)}>${token.content}</p>`;
398
407
  }
399
408
  };
400
409
  md.inline.ruler.after("escape", "math_inline", math_inline);
401
410
  md.block.ruler.after("blockquote", "math_block", math_block, {
402
411
  alt: ["paragraph", "reference", "blockquote", "list"]
403
412
  });
404
- md.renderer.rules.math_inline = (tokens, idx) => {
405
- return katexInline(tokens[idx].content);
406
- };
407
- md.renderer.rules.math_block = (tokens, idx) => {
408
- return katexBlock(tokens[idx].content, tokens[idx].map[0]) + "\n";
409
- };
413
+ md.renderer.rules.math_inline = katexInline;
414
+ md.renderer.rules.math_block = katexBlock;
410
415
  };
411
416
  const KatexPlugin$1 = KatexPlugin;
412
417
  const AdmonitionPlugin = (md, options) => {
@@ -420,7 +425,6 @@ const AdmonitionPlugin = (md, options) => {
420
425
  "class",
421
426
  `${prefix}-admonition ${prefix}-admonition-${token.info}`
422
427
  ]);
423
- tokens[idx].attrSet("data-line", String(tokens[idx].map[0]));
424
428
  } else if (token.type === "admonition_title_open") {
425
429
  tokens[idx].attrPush(["class", `${prefix}-admonition-title`]);
426
430
  }
@@ -544,7 +548,6 @@ const HeadingPlugin = (md, options) => {
544
548
  level
545
549
  });
546
550
  if (token.map && token.level === 0) {
547
- token.attrSet("data-line", String(token.map[0]));
548
551
  token.attrSet(
549
552
  "id",
550
553
  options.mdHeadingId(text, level, options.headsRef.value.length)
@@ -559,17 +562,22 @@ const HeadingPlugin = (md, options) => {
559
562
  const HeadingPlugin$1 = HeadingPlugin;
560
563
  const codetabs = (md, _opts) => {
561
564
  const defaultRender = md.renderer.rules.fence, unescapeAll = md.utils.unescapeAll, re = /\[(\w*)(?::([\w ]*))?\]/;
562
- function getInfo(token) {
565
+ const getInfo = (token) => {
563
566
  return token.info ? unescapeAll(token.info).trim() : "";
564
- }
565
- function getGroupAndTab(token) {
567
+ };
568
+ const getGroupAndTab = (token) => {
566
569
  const info = getInfo(token), [group = null, tab = ""] = (re.exec(info) || []).slice(1);
567
570
  return [group, tab];
568
- }
569
- function getLangName(token) {
571
+ };
572
+ const getLangName = (token) => {
570
573
  const info = getInfo(token);
571
574
  return info ? info.split(/(\s+)/g)[0] : "";
572
- }
575
+ };
576
+ const getTagType = (token) => {
577
+ const open = token.content.trim().split("\n").length < _opts.autoFoldThreshold;
578
+ const tagContainer = _opts.codeFoldable ? "details" : "div", tagHeader = _opts.codeFoldable ? "summary" : "div";
579
+ return { open, tagContainer, tagHeader };
580
+ };
573
581
  const fenceGroup = (tokens, idx, options, env, slf) => {
574
582
  var _a, _b;
575
583
  if (tokens[idx].hidden) {
@@ -577,10 +585,14 @@ const codetabs = (md, _opts) => {
577
585
  }
578
586
  const [GROUP] = getGroupAndTab(tokens[idx]);
579
587
  if (GROUP === null) {
580
- const open2 = tokens[idx].content.trim().split("\n").length < _opts.autoFoldThreshold;
581
- const tagContainer2 = _opts.codeFoldable ? "details" : "div", tagHeader2 = _opts.codeFoldable ? "summary" : "div";
588
+ const { open: open2, tagContainer: tagContainer2, tagHeader: tagHeader2 } = getTagType(tokens[idx]);
589
+ const addAttrs2 = [["class", `${prefix}-code`]];
590
+ open2 && addAttrs2.push(["open", ""]);
591
+ const tmpToken2 = {
592
+ attrs: mergeAttrs(tokens[idx], addAttrs2)
593
+ };
582
594
  const codeRendered = defaultRender(tokens, idx, options, env, slf);
583
- return `<${tagContainer2} class="${prefix}-code"${open2 ? " open" : ""}>
595
+ return `<${tagContainer2} ${slf.renderAttrs(tmpToken2)}>
584
596
  <${tagHeader2} class="${prefix}-code-head">
585
597
  <div class="${prefix}-code-flag">
586
598
  <span></span>
@@ -594,8 +606,12 @@ const codetabs = (md, _opts) => {
594
606
  </${tagHeader2}>${codeRendered}</${tagContainer2}>`;
595
607
  }
596
608
  let token, group, tab, checked, labels = "", pres = "", langs = "";
597
- const open = tokens[idx].content.trim().split("\n").length < _opts.autoFoldThreshold;
598
- const tagContainer = _opts.codeFoldable ? "details" : "div", tagHeader = _opts.codeFoldable ? "summary" : "div";
609
+ const { open, tagContainer, tagHeader } = getTagType(tokens[idx]);
610
+ const addAttrs = [["class", `${prefix}-code`]];
611
+ open && addAttrs.push(["open", ""]);
612
+ const tmpToken = {
613
+ attrs: mergeAttrs(tokens[idx], addAttrs)
614
+ };
599
615
  for (let i = idx; i < tokens.length; i++) {
600
616
  token = tokens[i];
601
617
  [group, tab] = getGroupAndTab(token);
@@ -615,7 +631,7 @@ const codetabs = (md, _opts) => {
615
631
  langs += `<input type="radio" name="${prefix}-codetab-lang-${_opts.editorId}-${idx}" class="${className}" ${checked}>
616
632
  <span class=${prefix}-code-lang>${getLangName(token)}</span>`;
617
633
  }
618
- return `<${tagContainer} class="${prefix}-code" ${open ? " open" : ""}>
634
+ return `<${tagContainer} ${slf.renderAttrs(tmpToken)}>
619
635
  <${tagHeader} class="${prefix}-code-head">
620
636
  <div class="${prefix}-code-flag">
621
637
  <ul class="${prefix}-codetab-label">${labels}</ul>
@@ -630,37 +646,16 @@ const codetabs = (md, _opts) => {
630
646
  };
631
647
  const CodePlugin = codetabs;
632
648
  const initLineNumber = (md) => {
633
- [
634
- "paragraph_open",
635
- "table_open",
636
- "ordered_list_open",
637
- "bullet_list_open",
638
- "blockquote_open",
639
- "hr",
640
- "html_block",
641
- "fence"
642
- ].forEach((rule) => {
643
- const backup = md.renderer.rules[rule];
644
- if (!backup) {
645
- md.renderer.rules[rule] = (tokens, idx, options, _env, self) => {
646
- let line;
647
- if (tokens[idx].map && tokens[idx].level === 0) {
648
- line = tokens[idx].map[0];
649
- tokens[idx].attrSet("data-line", String(line));
650
- }
651
- return self.renderToken(tokens, idx, options);
652
- };
653
- } else {
654
- md.renderer.rules[rule] = (tokens, idx, options, env, self) => {
655
- let line;
656
- const _htmlCode = backup(tokens, idx, options, env, self);
657
- if (tokens[idx].map && tokens[idx].level === 0 && !/^<!--/.test(_htmlCode)) {
658
- line = tokens[idx].map[0];
659
- return _htmlCode.replace(/^(<[^>]*)/, `$1 data-line="${line}"`);
649
+ md.core.ruler.push("init-line-number", (state) => {
650
+ state.tokens.forEach((token) => {
651
+ if (token.map) {
652
+ if (!token.attrs) {
653
+ token.attrs = [];
660
654
  }
661
- return _htmlCode;
662
- };
663
- }
655
+ token.attrs.push(["data-line", token.map[0].toString()]);
656
+ }
657
+ });
658
+ return true;
664
659
  });
665
660
  };
666
661
  const useMarkdownIt = (props, previewOnly) => {
@@ -1,7 +1,7 @@
1
1
  import { default as markdownit } from 'markdown-it';
2
2
  import { ShallowRef } from 'vue';
3
3
 
4
- declare const KatexPlugin: (md: markdownit, options: {
4
+ declare const KatexPlugin: (md: markdownit, { katexRef }: {
5
5
  katexRef: ShallowRef;
6
6
  }) => void;
7
7
  export default KatexPlugin;
@@ -0,0 +1,6 @@
1
+ import { Token } from 'markdown-it';
2
+
3
+ export declare const mergeAttrs: (token: Token, addAttrs: [
4
+ string,
5
+ string
6
+ ][]) => [string, string][];