vditor 4.0.0 → 4.0.2-alpha.0

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.
@@ -152,12 +152,27 @@
152
152
  margin-bottom: 16px;
153
153
  }
154
154
 
155
- blockquote {
156
- padding: 0 1em;
157
- color: #6a737d;
158
- border-left: 0.25em solid #eaecef;
155
+ blockquote:not(.callout) {
156
+ position: relative;
157
+ display: flex;
158
+ flex-direction: column;
159
+ padding: 0 0 0 calc(0.25em + 6px);
160
+ color: var(--blockquote-text-color, #5f6368);
161
+ background-color: transparent;
162
+ border: 0;
159
163
  margin: 0 0 16px 0;
160
164
 
165
+ &::before {
166
+ position: absolute;
167
+ top: 6px;
168
+ bottom: 6px;
169
+ left: 2px;
170
+ width: 0.25em;
171
+ content: "";
172
+ background-color: var(--blockquote-border-color, #e0e0e0);
173
+ border-radius: 6px;
174
+ }
175
+
161
176
  & > :first-child {
162
177
  margin-top: 0;
163
178
  }
@@ -165,6 +180,13 @@
165
180
  & > :last-child {
166
181
  margin-bottom: 0;
167
182
  }
183
+
184
+ & > p {
185
+ padding: 4px;
186
+ margin: 2px 0;
187
+ line-height: 1.625;
188
+ border-radius: 6px;
189
+ }
168
190
  }
169
191
 
170
192
  ins > iframe {
@@ -652,69 +674,99 @@
652
674
  .vditor-reset .callout,
653
675
  .vditor-wysiwyg blockquote.callout,
654
676
  .vditor-ir blockquote.callout {
655
- --callout-color: var(--callout-note-color, #0969da);
656
- --callout-background-color: var(--callout-note-background-color, rgba(9, 105, 218, 0.08));
677
+ --callout-color: var(--callout-note-color, #3575f0);
657
678
  position: relative;
679
+ display: flex;
680
+ flex-direction: column;
658
681
  margin: 0 0 16px;
659
- padding: 0.75em 1em;
660
- color: inherit;
661
- background-color: var(--callout-background-color);
682
+ padding: 0 0 0 calc(0.25em + 6px);
683
+ color: var(--blockquote-text-color, #5f6368);
662
684
  border: 0;
663
- border-left: 0.25em solid var(--callout-color);
685
+
686
+ &::before {
687
+ position: absolute;
688
+ top: 6px;
689
+ bottom: 6px;
690
+ left: 2px;
691
+ width: 0.25em;
692
+ content: "";
693
+ background-color: var(--callout-color);
694
+ border-radius: 6px;
695
+ }
664
696
 
665
697
  &[data-subtype="TIP"] {
666
- --callout-color: var(--callout-tip-color, #1a7f37);
667
- --callout-background-color: var(--callout-tip-background-color, rgba(26, 127, 55, 0.08));
698
+ --callout-color: var(--callout-tip-color, #65b84d);
668
699
  }
669
700
 
670
701
  &[data-subtype="IMPORTANT"] {
671
- --callout-color: var(--callout-important-color, #8250df);
672
- --callout-background-color: var(--callout-important-background-color, rgba(130, 80, 223, 0.08));
702
+ --callout-color: var(--callout-important-color, #8957e5);
673
703
  }
674
704
 
675
705
  &[data-subtype="WARNING"] {
676
- --callout-color: var(--callout-warning-color, #9a6700);
677
- --callout-background-color: var(--callout-warning-background-color, rgba(154, 103, 0, 0.08));
706
+ --callout-color: var(--callout-warning-color, #ff9632);
678
707
  }
679
708
 
680
709
  &[data-subtype="CAUTION"] {
681
- --callout-color: var(--callout-caution-color, #cf222e);
682
- --callout-background-color: var(--callout-caution-background-color, rgba(207, 34, 46, 0.08));
710
+ --callout-color: var(--callout-caution-color, #d23f31);
683
711
  }
684
712
 
685
713
  > .callout-info {
686
714
  display: flex;
687
715
  align-items: center;
688
716
  min-height: 1.5em;
689
- margin: 0 0 0.5em;
717
+ margin: 2px 0;
718
+ padding: 4px;
690
719
  color: var(--callout-color);
691
- font-weight: 600;
692
720
 
693
721
  .callout-icon {
694
- display: inline-flex;
722
+ display: flex;
695
723
  align-items: center;
696
- margin-right: 0.35em;
724
+ justify-content: center;
725
+ width: 1.2em;
726
+ height: 1.2em;
727
+ padding: 4px;
728
+ line-height: 1.2em;
729
+ text-align: center;
730
+ font-variant-emoji: emoji;
731
+ border-radius: 6px;
732
+
733
+ &:empty {
734
+ display: none;
735
+ }
697
736
  }
698
737
 
699
738
  .callout-title {
739
+ flex: 1;
700
740
  min-width: 1px;
741
+ margin-left: 4px;
742
+ font-size: 114%;
743
+ font-weight: 500;
744
+ opacity: 0.86;
701
745
  }
702
746
 
703
747
  .callout-img,
704
748
  > .callout-img {
705
- width: 1.2em;
706
749
  height: 1.2em;
707
- margin-right: 0.35em;
708
- object-fit: contain;
750
+ width: 100%;
709
751
  }
710
752
  }
711
753
 
712
- > .callout-content > :last-child,
713
- > :last-child {
714
- margin-bottom: 0;
754
+ > p:not(.callout-info),
755
+ > .callout-content > p {
756
+ padding: 4px;
757
+ margin: 2px 0;
758
+ line-height: 1.625;
759
+ border-radius: 6px;
715
760
  }
716
761
  }
717
762
 
763
+ .vditor-wysiwyg blockquote.callout > .callout-info,
764
+ .vditor-ir blockquote.callout > .callout-info {
765
+ font-size: 114%;
766
+ font-weight: 500;
767
+ opacity: 0.86;
768
+ }
769
+
718
770
  .vditor-wysiwyg__callout-marker {
719
771
  display: none;
720
772
  }
@@ -52,6 +52,15 @@
52
52
  }
53
53
 
54
54
  &__block {
55
+ // Source visibility is serialized both by Lute and by CSSStyleDeclaration.
56
+ // Keep the preview laid out for asynchronous wrapped line-number measurements.
57
+ &[data-type="code-block"] > pre:not([style*="display:none"]):not([style*="display: none"]) + .vditor-code__preview {
58
+ height: 0;
59
+ min-height: 0;
60
+ overflow: hidden;
61
+ visibility: hidden;
62
+ }
63
+
55
64
  pre:first-child {
56
65
  margin-bottom: -1em;
57
66
 
@@ -37,16 +37,13 @@
37
37
  --count-background-color: rgba(27, 31, 35, 0.05);
38
38
  --heading-border-color: #eaecef;
39
39
  --blockquote-color: #6a737d;
40
- --callout-note-color: #0969da;
41
- --callout-note-background-color: rgba(9, 105, 218, 0.08);
42
- --callout-tip-color: #1a7f37;
43
- --callout-tip-background-color: rgba(26, 127, 55, 0.08);
44
- --callout-important-color: #8250df;
45
- --callout-important-background-color: rgba(130, 80, 223, 0.08);
46
- --callout-warning-color: #9a6700;
47
- --callout-warning-background-color: rgba(154, 103, 0, 0.08);
48
- --callout-caution-color: #cf222e;
49
- --callout-caution-background-color: rgba(207, 34, 46, 0.08);
40
+ --blockquote-border-color: #e0e0e0;
41
+ --blockquote-text-color: #5f6368;
42
+ --callout-note-color: #3575f0;
43
+ --callout-tip-color: #65b84d;
44
+ --callout-important-color: #8957e5;
45
+ --callout-warning-color: #ff9632;
46
+ --callout-caution-color: #d23f31;
50
47
 
51
48
  --ir-heading-color: #660e7a;
52
49
  --ir-title-color: #808080;
@@ -77,16 +74,13 @@
77
74
  --count-background-color: rgba(@blurColor, 0.36);
78
75
  --heading-border-color: var(--textarea-text-color);
79
76
  --blockquote-color: var(--toolbar-icon-color);
80
- --callout-note-color: #58a6ff;
81
- --callout-note-background-color: rgba(56, 139, 253, 0.15);
82
- --callout-tip-color: #3fb950;
83
- --callout-tip-background-color: rgba(46, 160, 67, 0.15);
84
- --callout-important-color: #a371f7;
85
- --callout-important-background-color: rgba(163, 113, 247, 0.15);
86
- --callout-warning-color: #d29922;
87
- --callout-warning-background-color: rgba(187, 128, 9, 0.15);
88
- --callout-caution-color: #f85149;
89
- --callout-caution-background-color: rgba(248, 81, 73, 0.15);
77
+ --blockquote-border-color: rgba(230, 230, 230, 0.1);
78
+ --blockquote-text-color: #9aa0a6;
79
+ --callout-note-color: #3575f0;
80
+ --callout-tip-color: #65b84d;
81
+ --callout-important-color: #b388ff;
82
+ --callout-warning-color: #ff9632;
83
+ --callout-caution-color: #d23f31;
90
84
 
91
85
  --ir-heading-color: #9876aa;
92
86
  --ir-title-color: #808080;
package/src/index.ts CHANGED
@@ -557,6 +557,7 @@ class Vditor extends VditorMethod {
557
557
  this.vditor.lute = setLute({
558
558
  autoSpace: this.vditor.options.preview.markdown.autoSpace,
559
559
  callout: this.vditor.options.preview.markdown.callout,
560
+ inlineMath: this.vditor.options.preview.markdown.inlineMath,
560
561
  gfmAutoLink: this.vditor.options.preview.markdown.gfmAutoLink,
561
562
  codeBlockPreview: this.vditor.options.preview.markdown
562
563
  .codeBlockPreview,
@@ -52,6 +52,7 @@ export abstract class Constants {
52
52
  public static readonly MARKDOWN_OPTIONS = {
53
53
  autoSpace: false,
54
54
  callout: true,
55
+ inlineMath: true,
55
56
  gfmAutoLink: true,
56
57
  codeBlockPreview: true,
57
58
  fixTermTypo: false,
@@ -37,6 +37,7 @@ window.addEventListener("message", (e) => {
37
37
  cdn: "${vditor.options.cdn}",
38
38
  markdown: {
39
39
  callout: ${JSON.stringify(vditor.options.preview.markdown.callout)},
40
+ inlineMath: ${JSON.stringify(vditor.options.preview.markdown.inlineMath)},
40
41
  theme: ${JSON.stringify(vditor.options.preview.theme)}
41
42
  },
42
43
  hljs: {
@@ -1,13 +1,15 @@
1
1
  import {getSearch} from "../util/function";
2
2
 
3
- const videoRender = (element: HTMLElement, url: string) => {
4
- element.insertAdjacentHTML("afterend", `<video controls="controls" src="${url}"></video>`);
5
- element.remove();
6
- };
7
-
8
- const audioRender = (element: HTMLElement, url: string) => {
9
- element.insertAdjacentHTML("afterend", `<audio controls="controls" src="${url}"></audio>`);
10
- element.remove();
3
+ const replaceMedia = (element: HTMLElement, tag: "video" | "audio" | "iframe", url: string) => {
4
+ const media = element.ownerDocument.createElement(tag);
5
+ if (tag === "iframe") {
6
+ media.className = "iframe__video";
7
+ } else {
8
+ media.setAttribute("controls", "controls");
9
+ }
10
+ // 链接属性经 DOM 解码后可能包含引号,直接设置属性以保留 URL 的数据语义。
11
+ media.setAttribute("src", url);
12
+ element.replaceWith(media);
11
13
  };
12
14
 
13
15
  const iframeRender = (element: HTMLElement, url: string) => {
@@ -21,33 +23,20 @@ const iframeRender = (element: HTMLElement, url: string) => {
21
23
  const tedMatch = url.match(/(?:www\.|\/\/)ted\.com\/talks\/(\w+)/);
22
24
 
23
25
  if (youtubeMatch && youtubeMatch[1].length === 11) {
24
- element.insertAdjacentHTML("afterend",
25
- `<iframe class="iframe__video" src="//www.youtube.com/embed/${youtubeMatch[1] +
26
- (youtubeMatch[2] ? "?start=" + youtubeMatch[2] : "")}"></iframe>`);
27
- element.remove();
26
+ replaceMedia(element, "iframe", `//www.youtube.com/embed/${youtubeMatch[1] +
27
+ (youtubeMatch[2] ? "?start=" + youtubeMatch[2] : "")}`);
28
28
  } else if (youkuMatch && youkuMatch[1]) {
29
- element.insertAdjacentHTML("afterend",
30
- `<iframe class="iframe__video" src="//player.youku.com/embed/${youkuMatch[1]}"></iframe>`);
31
- element.remove();
29
+ replaceMedia(element, "iframe", `//player.youku.com/embed/${youkuMatch[1]}`);
32
30
  } else if (qqMatch && qqMatch[1]) {
33
- element.insertAdjacentHTML("afterend",
34
- `<iframe class="iframe__video" src="https://v.qq.com/txp/iframe/player.html?vid=${qqMatch[1]}"></iframe>`);
35
- element.remove();
31
+ replaceMedia(element, "iframe", `https://v.qq.com/txp/iframe/player.html?vid=${qqMatch[1]}`);
36
32
  } else if (coubMatch && coubMatch[1]) {
37
- element.insertAdjacentHTML("afterend",
38
- `<iframe class="iframe__video"
39
- src="//coub.com/embed/${coubMatch[1]}?muted=false&autostart=false&originalSize=true&startWithHD=true"></iframe>`);
40
- element.remove();
33
+ replaceMedia(element, "iframe",
34
+ `//coub.com/embed/${coubMatch[1]}?muted=false&autostart=false&originalSize=true&startWithHD=true`);
41
35
  } else if (facebookMatch && facebookMatch[0]) {
42
- element.insertAdjacentHTML("afterend",
43
- `<iframe class="iframe__video"
44
- src="https://www.facebook.com/plugins/video.php?href=${encodeURIComponent(facebookMatch[0])}"></iframe>`);
45
- element.remove();
36
+ replaceMedia(element, "iframe",
37
+ `https://www.facebook.com/plugins/video.php?href=${encodeURIComponent(facebookMatch[0])}`);
46
38
  } else if (dailymotionMatch && dailymotionMatch[2]) {
47
- element.insertAdjacentHTML("afterend",
48
- `<iframe class="iframe__video"
49
- src="https://www.dailymotion.com/embed/video/${dailymotionMatch[2]}"></iframe>`);
50
- element.remove();
39
+ replaceMedia(element, "iframe", `https://www.dailymotion.com/embed/video/${dailymotionMatch[2]}`);
51
40
  } else if (url.indexOf("bilibili.com") > -1 && (url.indexOf("bvid=") > -1 || (bilibiliMatch && bilibiliMatch[1]))) {
52
41
  const params: IObject = {
53
42
  bvid: getSearch("bvid", url) || (bilibiliMatch && bilibiliMatch[1]),
@@ -75,13 +64,9 @@ const iframeRender = (element: HTMLElement, url: string) => {
75
64
  src += "&";
76
65
  }
77
66
  });
78
- element.insertAdjacentHTML("afterend",
79
- `<iframe class="iframe__video" src="${src}"></iframe>`);
80
- element.remove();
67
+ replaceMedia(element, "iframe", src);
81
68
  } else if (tedMatch && tedMatch[1]) {
82
- element.insertAdjacentHTML("afterend",
83
- `<iframe class="iframe__video" src="//embed.ted.com/talks/${tedMatch[1]}"></iframe>`);
84
- element.remove();
69
+ replaceMedia(element, "iframe", `//embed.ted.com/talks/${tedMatch[1]}`);
85
70
  }
86
71
  };
87
72
 
@@ -95,9 +80,9 @@ export const mediaRender = (element: HTMLElement) => {
95
80
  return;
96
81
  }
97
82
  if (url.match(/^.+.(mp4|m4v|ogg|ogv|webm)$/)) {
98
- videoRender(aElement, url);
83
+ replaceMedia(aElement, "video", url);
99
84
  } else if (url.match(/^.+.(mp3|wav|flac)$/)) {
100
- audioRender(aElement, url);
85
+ replaceMedia(aElement, "audio", url);
101
86
  } else {
102
87
  iframeRender(aElement, url);
103
88
  }
@@ -13,7 +13,7 @@ export const mermaidRender = (element: (HTMLElement | Document) = document, cdn
13
13
  if (mermaidElements.length === 0) {
14
14
  return;
15
15
  }
16
- addScript(`${cdn}/dist/js/mermaid/mermaid.min.js?v=11.16.1`, "vditorMermaidScript").then(() => {
16
+ addScript(`${cdn}/dist/js/mermaid/mermaid.min.js?v=11.17.2`, "vditorMermaidScript").then(() => {
17
17
  const config: any = {
18
18
  securityLevel: "loose", // 升级后无 https://github.com/siyuan-note/siyuan/issues/3587,可使用该选项
19
19
  altFontFamily: "sans-serif",
@@ -62,6 +62,7 @@ export const md2html = (mdText: string, options?: IPreviewOptions) => {
62
62
  const lute = setLute({
63
63
  autoSpace: mergedOptions.markdown.autoSpace,
64
64
  callout: mergedOptions.markdown.callout,
65
+ inlineMath: mergedOptions.markdown.inlineMath,
65
66
  gfmAutoLink: mergedOptions.markdown.gfmAutoLink,
66
67
  codeBlockPreview: mergedOptions.markdown.codeBlockPreview,
67
68
  emojiSite: mergedOptions.emojiPath,
@@ -6,6 +6,7 @@ export const setLute = (options: ILuteOptions) => {
6
6
  lute.SetInlineMathAllowDigitAfterOpenMarker(options.inlineMathDigit);
7
7
  lute.SetAutoSpace(options.autoSpace);
8
8
  lute.SetCallout(options.callout);
9
+ lute.SetInlineMath(options.inlineMath);
9
10
  lute.SetToC(options.toc);
10
11
  lute.SetFootnotes(options.footnotes);
11
12
  lute.SetFixTermTypo(options.fixTermTypo);
@@ -60,6 +60,7 @@ export const processCodeRender = (previewPanel: HTMLElement, vditor: IVditor) =>
60
60
  if (!previewPanel) {
61
61
  return;
62
62
  }
63
+ previewPanel.classList.remove("vditor-code__preview");
63
64
  if (previewPanel.parentElement.getAttribute("data-type") === "html-block") {
64
65
  previewPanel.setAttribute("data-render", "1");
65
66
  return;
@@ -95,6 +96,7 @@ export const processCodeRender = (previewPanel: HTMLElement, vditor: IVditor) =>
95
96
  }
96
97
  })
97
98
  if (!cRender) {
99
+ previewPanel.classList.add("vditor-code__preview");
98
100
  highlightRender(Object.assign({}, vditor.options.preview.hljs), previewPanel, vditor.options.cdn);
99
101
  codeRender(previewPanel, vditor.options.preview.hljs);
100
102
  }