md-editor-v3 4.15.0 → 4.15.1-1

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;
@@ -537,7 +537,7 @@ const HeadingPlugin = (md, options) => {
537
537
  var _a;
538
538
  const token = tokens[idx];
539
539
  const text = ((_a = tokens[idx + 1].children) == null ? void 0 : _a.reduce((p, c) => {
540
- return p + (c.content || "");
540
+ return p + c.type === "text" ? c.content || "" : "";
541
541
  }, "")) || "";
542
542
  const level = token.markup.length;
543
543
  options.headsRef.value.push({
@@ -558,19 +558,36 @@ const HeadingPlugin = (md, options) => {
558
558
  };
559
559
  };
560
560
  const HeadingPlugin$1 = HeadingPlugin;
561
+ const mergeAttrs = (token, open) => {
562
+ const i = token.attrIndex("class");
563
+ const tmpAttrs = token.attrs ? token.attrs.slice() : [];
564
+ if (i < 0) {
565
+ tmpAttrs.push(["class", `${config.prefix}-code`]);
566
+ } else {
567
+ tmpAttrs[i] = tmpAttrs[i].slice();
568
+ tmpAttrs[i][1] += ` ${config.prefix}-code"`;
569
+ }
570
+ open && tmpAttrs.push(["open", ""]);
571
+ return tmpAttrs;
572
+ };
561
573
  const codetabs = (md, _opts) => {
562
574
  const defaultRender = md.renderer.rules.fence, unescapeAll = md.utils.unescapeAll, re = /\[(\w*)(?::([\w ]*))?\]/;
563
- function getInfo(token) {
575
+ const getInfo = (token) => {
564
576
  return token.info ? unescapeAll(token.info).trim() : "";
565
- }
566
- function getGroupAndTab(token) {
577
+ };
578
+ const getGroupAndTab = (token) => {
567
579
  const info = getInfo(token), [group = null, tab = ""] = (re.exec(info) || []).slice(1);
568
580
  return [group, tab];
569
- }
570
- function getLangName(token) {
581
+ };
582
+ const getLangName = (token) => {
571
583
  const info = getInfo(token);
572
584
  return info ? info.split(/(\s+)/g)[0] : "";
573
- }
585
+ };
586
+ const getTagType = (token) => {
587
+ const open = token.content.trim().split("\n").length < _opts.autoFoldThreshold;
588
+ const tagContainer = _opts.codeFoldable ? "details" : "div", tagHeader = _opts.codeFoldable ? "summary" : "div";
589
+ return { open, tagContainer, tagHeader };
590
+ };
574
591
  const fenceGroup = (tokens, idx, options, env, slf) => {
575
592
  var _a, _b;
576
593
  if (tokens[idx].hidden) {
@@ -578,10 +595,12 @@ const codetabs = (md, _opts) => {
578
595
  }
579
596
  const [GROUP] = getGroupAndTab(tokens[idx]);
580
597
  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";
598
+ const { open: open2, tagContainer: tagContainer2, tagHeader: tagHeader2 } = getTagType(tokens[idx]);
599
+ const tmpToken2 = {
600
+ attrs: mergeAttrs(tokens[idx], open2)
601
+ };
583
602
  const codeRendered = defaultRender(tokens, idx, options, env, slf);
584
- return `<${tagContainer2} class="${config.prefix}-code"${open2 ? " open" : ""}>
603
+ return `<${tagContainer2} ${slf.renderAttrs(tmpToken2)}>
585
604
  <${tagHeader2} class="${config.prefix}-code-head">
586
605
  <div class="${config.prefix}-code-flag">
587
606
  <span></span>
@@ -595,8 +614,10 @@ const codetabs = (md, _opts) => {
595
614
  </${tagHeader2}>${codeRendered}</${tagContainer2}>`;
596
615
  }
597
616
  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";
617
+ const { open, tagContainer, tagHeader } = getTagType(tokens[idx]);
618
+ const tmpToken = {
619
+ attrs: mergeAttrs(tokens[idx], open)
620
+ };
600
621
  for (let i = idx; i < tokens.length; i++) {
601
622
  token = tokens[i];
602
623
  [group, tab] = getGroupAndTab(token);
@@ -616,7 +637,7 @@ const codetabs = (md, _opts) => {
616
637
  langs += `<input type="radio" name="${config.prefix}-codetab-lang-${_opts.editorId}-${idx}" class="${className}" ${checked}>
617
638
  <span class=${config.prefix}-code-lang>${getLangName(token)}</span>`;
618
639
  }
619
- return `<${tagContainer} class="${config.prefix}-code" ${open ? " open" : ""}>
640
+ return `<${tagContainer} ${slf.renderAttrs(tmpToken)}>
620
641
  <${tagHeader} class="${config.prefix}-code-head">
621
642
  <div class="${config.prefix}-code-flag">
622
643
  <ul class="${config.prefix}-codetab-label">${labels}</ul>
@@ -631,37 +652,16 @@ const codetabs = (md, _opts) => {
631
652
  };
632
653
  const CodePlugin = codetabs;
633
654
  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}"`);
655
+ md.core.ruler.push("init-line-number", (state) => {
656
+ state.tokens.forEach((token) => {
657
+ if (token.map) {
658
+ if (!token.attrs) {
659
+ token.attrs = [];
661
660
  }
662
- return _htmlCode;
663
- };
664
- }
661
+ token.attrs.push(["data-line", token.map[0].toString()]);
662
+ }
663
+ });
664
+ return true;
665
665
  });
666
666
  };
667
667
  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;
@@ -536,7 +536,7 @@ const HeadingPlugin = (md, options) => {
536
536
  var _a;
537
537
  const token = tokens[idx];
538
538
  const text = ((_a = tokens[idx + 1].children) == null ? void 0 : _a.reduce((p, c) => {
539
- return p + (c.content || "");
539
+ return p + c.type === "text" ? c.content || "" : "";
540
540
  }, "")) || "";
541
541
  const level = token.markup.length;
542
542
  options.headsRef.value.push({
@@ -557,19 +557,36 @@ const HeadingPlugin = (md, options) => {
557
557
  };
558
558
  };
559
559
  const HeadingPlugin$1 = HeadingPlugin;
560
+ const mergeAttrs = (token, open) => {
561
+ const i = token.attrIndex("class");
562
+ const tmpAttrs = token.attrs ? token.attrs.slice() : [];
563
+ if (i < 0) {
564
+ tmpAttrs.push(["class", `${prefix}-code`]);
565
+ } else {
566
+ tmpAttrs[i] = tmpAttrs[i].slice();
567
+ tmpAttrs[i][1] += ` ${prefix}-code"`;
568
+ }
569
+ open && tmpAttrs.push(["open", ""]);
570
+ return tmpAttrs;
571
+ };
560
572
  const codetabs = (md, _opts) => {
561
573
  const defaultRender = md.renderer.rules.fence, unescapeAll = md.utils.unescapeAll, re = /\[(\w*)(?::([\w ]*))?\]/;
562
- function getInfo(token) {
574
+ const getInfo = (token) => {
563
575
  return token.info ? unescapeAll(token.info).trim() : "";
564
- }
565
- function getGroupAndTab(token) {
576
+ };
577
+ const getGroupAndTab = (token) => {
566
578
  const info = getInfo(token), [group = null, tab = ""] = (re.exec(info) || []).slice(1);
567
579
  return [group, tab];
568
- }
569
- function getLangName(token) {
580
+ };
581
+ const getLangName = (token) => {
570
582
  const info = getInfo(token);
571
583
  return info ? info.split(/(\s+)/g)[0] : "";
572
- }
584
+ };
585
+ const getTagType = (token) => {
586
+ const open = token.content.trim().split("\n").length < _opts.autoFoldThreshold;
587
+ const tagContainer = _opts.codeFoldable ? "details" : "div", tagHeader = _opts.codeFoldable ? "summary" : "div";
588
+ return { open, tagContainer, tagHeader };
589
+ };
573
590
  const fenceGroup = (tokens, idx, options, env, slf) => {
574
591
  var _a, _b;
575
592
  if (tokens[idx].hidden) {
@@ -577,10 +594,12 @@ const codetabs = (md, _opts) => {
577
594
  }
578
595
  const [GROUP] = getGroupAndTab(tokens[idx]);
579
596
  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";
597
+ const { open: open2, tagContainer: tagContainer2, tagHeader: tagHeader2 } = getTagType(tokens[idx]);
598
+ const tmpToken2 = {
599
+ attrs: mergeAttrs(tokens[idx], open2)
600
+ };
582
601
  const codeRendered = defaultRender(tokens, idx, options, env, slf);
583
- return `<${tagContainer2} class="${prefix}-code"${open2 ? " open" : ""}>
602
+ return `<${tagContainer2} ${slf.renderAttrs(tmpToken2)}>
584
603
  <${tagHeader2} class="${prefix}-code-head">
585
604
  <div class="${prefix}-code-flag">
586
605
  <span></span>
@@ -594,8 +613,10 @@ const codetabs = (md, _opts) => {
594
613
  </${tagHeader2}>${codeRendered}</${tagContainer2}>`;
595
614
  }
596
615
  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";
616
+ const { open, tagContainer, tagHeader } = getTagType(tokens[idx]);
617
+ const tmpToken = {
618
+ attrs: mergeAttrs(tokens[idx], open)
619
+ };
599
620
  for (let i = idx; i < tokens.length; i++) {
600
621
  token = tokens[i];
601
622
  [group, tab] = getGroupAndTab(token);
@@ -615,7 +636,7 @@ const codetabs = (md, _opts) => {
615
636
  langs += `<input type="radio" name="${prefix}-codetab-lang-${_opts.editorId}-${idx}" class="${className}" ${checked}>
616
637
  <span class=${prefix}-code-lang>${getLangName(token)}</span>`;
617
638
  }
618
- return `<${tagContainer} class="${prefix}-code" ${open ? " open" : ""}>
639
+ return `<${tagContainer} ${slf.renderAttrs(tmpToken)}>
619
640
  <${tagHeader} class="${prefix}-code-head">
620
641
  <div class="${prefix}-code-flag">
621
642
  <ul class="${prefix}-codetab-label">${labels}</ul>
@@ -630,37 +651,16 @@ const codetabs = (md, _opts) => {
630
651
  };
631
652
  const CodePlugin = codetabs;
632
653
  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}"`);
654
+ md.core.ruler.push("init-line-number", (state) => {
655
+ state.tokens.forEach((token) => {
656
+ if (token.map) {
657
+ if (!token.attrs) {
658
+ token.attrs = [];
660
659
  }
661
- return _htmlCode;
662
- };
663
- }
660
+ token.attrs.push(["data-line", token.map[0].toString()]);
661
+ }
662
+ });
663
+ return true;
664
664
  });
665
665
  };
666
666
  const useMarkdownIt = (props, previewOnly) => {