md-editor-v3 4.15.1-1 → 4.15.1-3

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.
@@ -264,6 +264,19 @@ const MermaidPlugin = (md, options) => {
264
264
  };
265
265
  };
266
266
  const MermaidPlugin$1 = MermaidPlugin;
267
+ const mergeAttrs = (token, addAttrs) => {
268
+ const tmpAttrs = token.attrs ? token.attrs.slice() : [];
269
+ addAttrs.forEach((addAttr) => {
270
+ const i = token.attrIndex(addAttr[0]);
271
+ if (i < 0) {
272
+ tmpAttrs.push(addAttr);
273
+ } else {
274
+ tmpAttrs[i] = tmpAttrs[i].slice();
275
+ tmpAttrs[i][1] += ` ${addAttr[1]}`;
276
+ }
277
+ });
278
+ return tmpAttrs;
279
+ };
267
280
  const isValidDelim = (state, pos) => {
268
281
  let can_open = true, can_close = true;
269
282
  const max = state.posMax;
@@ -376,38 +389,42 @@ const math_block = (state, start, end, silent) => {
376
389
  token.markup = "$$";
377
390
  return true;
378
391
  };
379
- const KatexPlugin = (md, options) => {
380
- const katexInline = (str) => {
381
- if (options.katexRef.value) {
382
- const html = options.katexRef.value.renderToString(str, {
392
+ const KatexPlugin = (md, { katexRef }) => {
393
+ const katexInline = (tokens, idx, options, env, slf) => {
394
+ const token = tokens[idx];
395
+ const tmpToken = {
396
+ attrs: mergeAttrs(token, [["class", `${config.prefix}-katex-inline`]])
397
+ };
398
+ if (katexRef.value) {
399
+ const html = katexRef.value.renderToString(token.content, {
383
400
  throwOnError: false
384
401
  });
385
- return `<span class="${config.prefix}-katex-inline" data-processed>${html}</span>`;
402
+ return `<span ${slf.renderAttrs(tmpToken)} data-processed>${html}</span>`;
386
403
  } else {
387
- return `<span class="${config.prefix}-katex-inline">${str}</span>`;
404
+ return `<span ${slf.renderAttrs(tmpToken)}>${token.content}</span>`;
388
405
  }
389
406
  };
390
- const katexBlock = (str, lineNum) => {
391
- if (options.katexRef.value) {
392
- const html = options.katexRef.value.renderToString(str, {
407
+ const katexBlock = (tokens, idx, options, env, slf) => {
408
+ const token = tokens[idx];
409
+ const tmpToken = {
410
+ attrs: mergeAttrs(token, [["class", `${config.prefix}-katex-block`]])
411
+ };
412
+ if (katexRef.value) {
413
+ const html = katexRef.value.renderToString(token.content, {
393
414
  throwOnError: false,
394
415
  displayMode: true
395
416
  });
396
- return `<p class="${config.prefix}-katex-block" data-line=${lineNum} data-processed>${html}</p>`;
417
+ return `<p ${slf.renderAttrs(tmpToken)} data-processed>${html}</p>`;
397
418
  } else {
398
- return `<p class="${config.prefix}-katex-block" data-line=${lineNum}>${str}</p>`;
419
+ return `<p ${slf.renderAttrs(tmpToken)}>${token.content}</p>`;
399
420
  }
400
421
  };
401
422
  md.inline.ruler.after("escape", "math_inline", math_inline);
402
423
  md.block.ruler.after("blockquote", "math_block", math_block, {
403
424
  alt: ["paragraph", "reference", "blockquote", "list"]
404
425
  });
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
- };
426
+ md.renderer.rules.math_inline = katexInline;
427
+ md.renderer.rules.math_block = katexBlock;
411
428
  };
412
429
  const KatexPlugin$1 = KatexPlugin;
413
430
  const AdmonitionPlugin = (md, options) => {
@@ -421,7 +438,6 @@ const AdmonitionPlugin = (md, options) => {
421
438
  "class",
422
439
  `${config.prefix}-admonition ${config.prefix}-admonition-${token.info}`
423
440
  ]);
424
- tokens[idx].attrSet("data-line", String(tokens[idx].map[0]));
425
441
  } else if (token.type === "admonition_title_open") {
426
442
  tokens[idx].attrPush(["class", `${config.prefix}-admonition-title`]);
427
443
  }
@@ -545,7 +561,6 @@ const HeadingPlugin = (md, options) => {
545
561
  level
546
562
  });
547
563
  if (token.map && token.level === 0) {
548
- token.attrSet("data-line", String(token.map[0]));
549
564
  token.attrSet(
550
565
  "id",
551
566
  options.mdHeadingId(text, level, options.headsRef.value.length)
@@ -558,18 +573,6 @@ const HeadingPlugin = (md, options) => {
558
573
  };
559
574
  };
560
575
  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
- };
573
576
  const codetabs = (md, _opts) => {
574
577
  const defaultRender = md.renderer.rules.fence, unescapeAll = md.utils.unescapeAll, re = /\[(\w*)(?::([\w ]*))?\]/;
575
578
  const getInfo = (token) => {
@@ -596,8 +599,10 @@ const codetabs = (md, _opts) => {
596
599
  const [GROUP] = getGroupAndTab(tokens[idx]);
597
600
  if (GROUP === null) {
598
601
  const { open: open2, tagContainer: tagContainer2, tagHeader: tagHeader2 } = getTagType(tokens[idx]);
602
+ const addAttrs2 = [["class", `${config.prefix}-code`]];
603
+ open2 && addAttrs2.push(["open", ""]);
599
604
  const tmpToken2 = {
600
- attrs: mergeAttrs(tokens[idx], open2)
605
+ attrs: mergeAttrs(tokens[idx], addAttrs2)
601
606
  };
602
607
  const codeRendered = defaultRender(tokens, idx, options, env, slf);
603
608
  return `<${tagContainer2} ${slf.renderAttrs(tmpToken2)}>
@@ -615,8 +620,10 @@ const codetabs = (md, _opts) => {
615
620
  }
616
621
  let token, group, tab, checked, labels = "", pres = "", langs = "";
617
622
  const { open, tagContainer, tagHeader } = getTagType(tokens[idx]);
623
+ const addAttrs = [["class", `${config.prefix}-code`]];
624
+ open && addAttrs.push(["open", ""]);
618
625
  const tmpToken = {
619
- attrs: mergeAttrs(tokens[idx], open)
626
+ attrs: mergeAttrs(tokens[idx], addAttrs)
620
627
  };
621
628
  for (let i = idx; i < tokens.length; i++) {
622
629
  token = tokens[i];
@@ -263,6 +263,19 @@ const MermaidPlugin = (md, options) => {
263
263
  };
264
264
  };
265
265
  const MermaidPlugin$1 = MermaidPlugin;
266
+ const mergeAttrs = (token, addAttrs) => {
267
+ const tmpAttrs = token.attrs ? token.attrs.slice() : [];
268
+ addAttrs.forEach((addAttr) => {
269
+ const i = token.attrIndex(addAttr[0]);
270
+ if (i < 0) {
271
+ tmpAttrs.push(addAttr);
272
+ } else {
273
+ tmpAttrs[i] = tmpAttrs[i].slice();
274
+ tmpAttrs[i][1] += ` ${addAttr[1]}`;
275
+ }
276
+ });
277
+ return tmpAttrs;
278
+ };
266
279
  const isValidDelim = (state, pos) => {
267
280
  let can_open = true, can_close = true;
268
281
  const max = state.posMax;
@@ -375,38 +388,42 @@ const math_block = (state, start, end, silent) => {
375
388
  token.markup = "$$";
376
389
  return true;
377
390
  };
378
- const KatexPlugin = (md, options) => {
379
- const katexInline = (str) => {
380
- if (options.katexRef.value) {
381
- const html = options.katexRef.value.renderToString(str, {
391
+ const KatexPlugin = (md, { katexRef }) => {
392
+ const katexInline = (tokens, idx, options, env, slf) => {
393
+ const token = tokens[idx];
394
+ const tmpToken = {
395
+ attrs: mergeAttrs(token, [["class", `${prefix}-katex-inline`]])
396
+ };
397
+ if (katexRef.value) {
398
+ const html = katexRef.value.renderToString(token.content, {
382
399
  throwOnError: false
383
400
  });
384
- return `<span class="${prefix}-katex-inline" data-processed>${html}</span>`;
401
+ return `<span ${slf.renderAttrs(tmpToken)} data-processed>${html}</span>`;
385
402
  } else {
386
- return `<span class="${prefix}-katex-inline">${str}</span>`;
403
+ return `<span ${slf.renderAttrs(tmpToken)}>${token.content}</span>`;
387
404
  }
388
405
  };
389
- const katexBlock = (str, lineNum) => {
390
- if (options.katexRef.value) {
391
- const html = options.katexRef.value.renderToString(str, {
406
+ const katexBlock = (tokens, idx, options, env, slf) => {
407
+ const token = tokens[idx];
408
+ const tmpToken = {
409
+ attrs: mergeAttrs(token, [["class", `${prefix}-katex-block`]])
410
+ };
411
+ if (katexRef.value) {
412
+ const html = katexRef.value.renderToString(token.content, {
392
413
  throwOnError: false,
393
414
  displayMode: true
394
415
  });
395
- return `<p class="${prefix}-katex-block" data-line=${lineNum} data-processed>${html}</p>`;
416
+ return `<p ${slf.renderAttrs(tmpToken)} data-processed>${html}</p>`;
396
417
  } else {
397
- return `<p class="${prefix}-katex-block" data-line=${lineNum}>${str}</p>`;
418
+ return `<p ${slf.renderAttrs(tmpToken)}>${token.content}</p>`;
398
419
  }
399
420
  };
400
421
  md.inline.ruler.after("escape", "math_inline", math_inline);
401
422
  md.block.ruler.after("blockquote", "math_block", math_block, {
402
423
  alt: ["paragraph", "reference", "blockquote", "list"]
403
424
  });
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
- };
425
+ md.renderer.rules.math_inline = katexInline;
426
+ md.renderer.rules.math_block = katexBlock;
410
427
  };
411
428
  const KatexPlugin$1 = KatexPlugin;
412
429
  const AdmonitionPlugin = (md, options) => {
@@ -420,7 +437,6 @@ const AdmonitionPlugin = (md, options) => {
420
437
  "class",
421
438
  `${prefix}-admonition ${prefix}-admonition-${token.info}`
422
439
  ]);
423
- tokens[idx].attrSet("data-line", String(tokens[idx].map[0]));
424
440
  } else if (token.type === "admonition_title_open") {
425
441
  tokens[idx].attrPush(["class", `${prefix}-admonition-title`]);
426
442
  }
@@ -544,7 +560,6 @@ const HeadingPlugin = (md, options) => {
544
560
  level
545
561
  });
546
562
  if (token.map && token.level === 0) {
547
- token.attrSet("data-line", String(token.map[0]));
548
563
  token.attrSet(
549
564
  "id",
550
565
  options.mdHeadingId(text, level, options.headsRef.value.length)
@@ -557,18 +572,6 @@ const HeadingPlugin = (md, options) => {
557
572
  };
558
573
  };
559
574
  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
- };
572
575
  const codetabs = (md, _opts) => {
573
576
  const defaultRender = md.renderer.rules.fence, unescapeAll = md.utils.unescapeAll, re = /\[(\w*)(?::([\w ]*))?\]/;
574
577
  const getInfo = (token) => {
@@ -595,8 +598,10 @@ const codetabs = (md, _opts) => {
595
598
  const [GROUP] = getGroupAndTab(tokens[idx]);
596
599
  if (GROUP === null) {
597
600
  const { open: open2, tagContainer: tagContainer2, tagHeader: tagHeader2 } = getTagType(tokens[idx]);
601
+ const addAttrs2 = [["class", `${prefix}-code`]];
602
+ open2 && addAttrs2.push(["open", ""]);
598
603
  const tmpToken2 = {
599
- attrs: mergeAttrs(tokens[idx], open2)
604
+ attrs: mergeAttrs(tokens[idx], addAttrs2)
600
605
  };
601
606
  const codeRendered = defaultRender(tokens, idx, options, env, slf);
602
607
  return `<${tagContainer2} ${slf.renderAttrs(tmpToken2)}>
@@ -614,8 +619,10 @@ const codetabs = (md, _opts) => {
614
619
  }
615
620
  let token, group, tab, checked, labels = "", pres = "", langs = "";
616
621
  const { open, tagContainer, tagHeader } = getTagType(tokens[idx]);
622
+ const addAttrs = [["class", `${prefix}-code`]];
623
+ open && addAttrs.push(["open", ""]);
617
624
  const tmpToken = {
618
- attrs: mergeAttrs(tokens[idx], open)
625
+ attrs: mergeAttrs(tokens[idx], addAttrs)
619
626
  };
620
627
  for (let i = idx; i < tokens.length; i++) {
621
628
  token = tokens[i];
@@ -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][];