@yltrcc/vditor 0.0.6 → 0.0.8

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.
@@ -1,60 +1,60 @@
1
- import {code160to32} from "../util/code160to32";
2
-
3
- /**
4
- * 将 doclink DOM 元素转换回 Markdown 语法
5
- * 处理 <span class="vditor-doclink-wrapper" data-doc-markdown="((id 'text'))">text</span>
6
- */
7
- const processDocLinksInHTML = (html: string): string => {
8
- // 创建临时 DOM 元素来解析 HTML
9
- const tempDiv = document.createElement("div");
10
- tempDiv.innerHTML = html;
11
-
12
- // 查找所有 doclink wrapper 元素
13
- const docLinkWrappers = tempDiv.querySelectorAll(".vditor-doclink-wrapper");
14
- docLinkWrappers.forEach((wrapper) => {
15
- const markdown = wrapper.getAttribute("data-doc-markdown");
16
- if (markdown) {
17
- // 用文本节点替换整个 wrapper,内容为 Markdown 语法
18
- wrapper.replaceWith(document.createTextNode(markdown));
19
- } else {
20
- // 如果没有 data-doc-markdown,尝试从 data-doc-id 和 data-doc-text 重建
21
- const id = wrapper.getAttribute("data-doc-id");
22
- const text = wrapper.getAttribute("data-doc-text");
23
- if (id && text) {
24
- wrapper.replaceWith(document.createTextNode(`((${id} '${text}'))`));
25
- }
26
- }
27
- });
28
-
29
- // 也处理旧的 .vditor-doclink 元素(没有 wrapper 的情况)
30
- const docLinks = tempDiv.querySelectorAll(".vditor-doclink");
31
- docLinks.forEach((link) => {
32
- const markdown = link.getAttribute("data-doc-markdown");
33
- if (markdown) {
34
- link.replaceWith(document.createTextNode(markdown));
35
- } else {
36
- const id = link.getAttribute("data-doc-id");
37
- const text = link.getAttribute("data-doc-text");
38
- if (id && text) {
39
- link.replaceWith(document.createTextNode(`((${id} '${text}'))`));
40
- }
41
- }
42
- });
43
-
44
- return tempDiv.innerHTML;
45
- };
46
-
47
- export const getMarkdown = (vditor: IVditor) => {
48
- if (vditor.currentMode === "sv") {
49
- return code160to32(`${vditor.sv.element.textContent}\n`.replace(/\n\n$/, "\n"));
50
- } else if (vditor.currentMode === "wysiwyg") {
51
- // 先处理 doclink 元素,将其转换回 Markdown 语法
52
- const processedHTML = processDocLinksInHTML(vditor.wysiwyg.element.innerHTML);
53
- return vditor.lute.VditorDOM2Md(processedHTML);
54
- } else if (vditor.currentMode === "ir") {
55
- // 同样处理 IR 模式
56
- const processedHTML = processDocLinksInHTML(vditor.ir.element.innerHTML);
57
- return vditor.lute.VditorIRDOM2Md(processedHTML);
58
- }
59
- return "";
60
- };
1
+ import {code160to32} from "../util/code160to32";
2
+
3
+ /**
4
+ * 将 doclink DOM 元素转换回 Markdown 语法
5
+ * 处理 <span class="vditor-doclink-wrapper" data-doc-markdown="((id 'text'))">text</span>
6
+ */
7
+ const processDocLinksInHTML = (html: string): string => {
8
+ // 创建临时 DOM 元素来解析 HTML
9
+ const tempDiv = document.createElement("div");
10
+ tempDiv.innerHTML = html;
11
+
12
+ // 查找所有 doclink wrapper 元素
13
+ const docLinkWrappers = tempDiv.querySelectorAll(".vditor-doclink-wrapper");
14
+ docLinkWrappers.forEach((wrapper) => {
15
+ const markdown = wrapper.getAttribute("data-doc-markdown");
16
+ if (markdown) {
17
+ // 用文本节点替换整个 wrapper,内容为 Markdown 语法
18
+ wrapper.replaceWith(document.createTextNode(markdown));
19
+ } else {
20
+ // 如果没有 data-doc-markdown,尝试从 data-doc-id 和 data-doc-text 重建
21
+ const id = wrapper.getAttribute("data-doc-id");
22
+ const text = wrapper.getAttribute("data-doc-text");
23
+ if (id && text) {
24
+ wrapper.replaceWith(document.createTextNode(`((${id} '${text}'))`));
25
+ }
26
+ }
27
+ });
28
+
29
+ // 也处理旧的 .vditor-doclink 元素(没有 wrapper 的情况)
30
+ const docLinks = tempDiv.querySelectorAll(".vditor-doclink");
31
+ docLinks.forEach((link) => {
32
+ const markdown = link.getAttribute("data-doc-markdown");
33
+ if (markdown) {
34
+ link.replaceWith(document.createTextNode(markdown));
35
+ } else {
36
+ const id = link.getAttribute("data-doc-id");
37
+ const text = link.getAttribute("data-doc-text");
38
+ if (id && text) {
39
+ link.replaceWith(document.createTextNode(`((${id} '${text}'))`));
40
+ }
41
+ }
42
+ });
43
+
44
+ return tempDiv.innerHTML;
45
+ };
46
+
47
+ export const getMarkdown = (vditor: IVditor) => {
48
+ if (vditor.currentMode === "sv") {
49
+ return code160to32(`${vditor.sv.element.textContent}\n`.replace(/\n\n$/, "\n"));
50
+ } else if (vditor.currentMode === "wysiwyg") {
51
+ // 先处理 doclink 元素,将其转换回 Markdown 语法
52
+ const processedHTML = processDocLinksInHTML(vditor.wysiwyg.element.innerHTML);
53
+ return vditor.lute.VditorDOM2Md(processedHTML);
54
+ } else if (vditor.currentMode === "ir") {
55
+ // 同样处理 IR 模式
56
+ const processedHTML = processDocLinksInHTML(vditor.ir.element.innerHTML);
57
+ return vditor.lute.VditorIRDOM2Md(processedHTML);
58
+ }
59
+ return "";
60
+ };
@@ -1,43 +1,43 @@
1
- import {Constants, VDITOR_VERSION} from "../constants";
2
- import {getEventName} from "../util/compatibility";
3
- import {MenuItem} from "./MenuItem";
4
-
5
- export class Info extends MenuItem {
6
- constructor(vditor: IVditor, menuItem: IMenuItem) {
7
- super(vditor, menuItem);
8
- this.element.children[0].addEventListener(getEventName(), (event) => {
9
- event.preventDefault();
10
- vditor.tip.show(`<div style="max-width: 520px; font-size: 14px;line-height: 22px;margin-bottom: 14px;">
11
- <p style="text-align: center;margin: 14px 0">
12
- <em>下一代的 Markdown 编辑器,为未来而构建</em>
13
- </p>
14
- <div style="display: flex;margin-bottom: 14px;flex-wrap: wrap;align-items: center">
15
- <img src="${Constants.CDN}/dist/images/logo.png" style="margin: 0 auto;height: 68px"/>
16
- <div>&nbsp;&nbsp;</div>
17
- <div style="flex: 1;min-width: 250px">
18
- Vditor 是一款浏览器端的 Markdown 编辑器,支持所见即所得、即时渲染(类似 Typora)和分屏预览模式。
19
- 它使用 TypeScript 实现,支持原生 JavaScript 以及 Vue、React、Angular 和 Svelte 等框架。
20
- </div>
21
- </div>
22
- <div style="display: flex;flex-wrap: wrap;">
23
- <ul style="list-style: none;flex: 1;min-width:148px">
24
- <li>
25
- 项目地址:<a href="https://b3log.org/vditor" target="_blank">b3log.org/vditor</a>
26
- </li>
27
- <li>
28
- 开源协议:MIT
29
- </li>
30
- </ul>
31
- <ul style="list-style: none;margin-right: 18px">
32
- <li>
33
- 组件版本:Vditor v${VDITOR_VERSION} / Lute v${Lute.Version}
34
- </li>
35
- <li>
36
- 赞助捐赠:<a href="https://ld246.com/sponsor" target="_blank">https://ld246.com/sponsor</a>
37
- </li>
38
- </ul>
39
- </div>
40
- </div>`, 0);
41
- });
42
- }
43
- }
1
+ import {Constants, VDITOR_VERSION} from "../constants";
2
+ import {getEventName} from "../util/compatibility";
3
+ import {MenuItem} from "./MenuItem";
4
+
5
+ export class Info extends MenuItem {
6
+ constructor(vditor: IVditor, menuItem: IMenuItem) {
7
+ super(vditor, menuItem);
8
+ this.element.children[0].addEventListener(getEventName(), (event) => {
9
+ event.preventDefault();
10
+ vditor.tip.show(`<div style="max-width: 520px; font-size: 14px;line-height: 22px;margin-bottom: 14px;">
11
+ <p style="text-align: center;margin: 14px 0">
12
+ <em>下一代的 Markdown 编辑器,为未来而构建</em>
13
+ </p>
14
+ <div style="display: flex;margin-bottom: 14px;flex-wrap: wrap;align-items: center">
15
+ <img src="${Constants.CDN}/dist/images/logo.png" style="margin: 0 auto;height: 68px"/>
16
+ <div>&nbsp;&nbsp;</div>
17
+ <div style="flex: 1;min-width: 250px">
18
+ Vditor 是一款浏览器端的 Markdown 编辑器,支持所见即所得、即时渲染(类似 Typora)和分屏预览模式。
19
+ 它使用 TypeScript 实现,支持原生 JavaScript 以及 Vue、React、Angular 和 Svelte 等框架。
20
+ </div>
21
+ </div>
22
+ <div style="display: flex;flex-wrap: wrap;">
23
+ <ul style="list-style: none;flex: 1;min-width:148px">
24
+ <li>
25
+ 项目地址:<a href="https://b3log.org/vditor" target="_blank">b3log.org/vditor</a>
26
+ </li>
27
+ <li>
28
+ 开源协议:MIT
29
+ </li>
30
+ </ul>
31
+ <ul style="list-style: none;margin-right: 18px">
32
+ <li>
33
+ 组件版本:Vditor v${VDITOR_VERSION} / Lute v${Lute.Version}
34
+ </li>
35
+ <li>
36
+ 赞助捐赠:<a href="https://ld246.com/sponsor" target="_blank">https://ld246.com/sponsor</a>
37
+ </li>
38
+ </ul>
39
+ </div>
40
+ </div>`, 0);
41
+ });
42
+ }
43
+ }