Skip to content

Commit

Permalink
🐛 fix #534
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Jul 9, 2020
1 parent 69d1b44 commit e6f07e6
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
10 changes: 5 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@
* [open issues](https://github.com/Vanessa219/vditor/issues)
* [346](https://github.com/Vanessa219/vditor/issues/346) 内容主题推荐(长期有效) `改进功能`

### v3.3.5 / 2020-07-xx
### v3.3.6 / 2020-07-xx

### v3.3.5 / 2020-07-09

* [534](https://github.com/Vanessa219/vditor/issues/534) 支持导出到知乎 `引入特性`
* [552](https://github.com/Vanessa219/vditor/issues/552) blockquote 换行需逐层跳出 `修复缺陷`
* [551](https://github.com/Vanessa219/vditor/issues/551) Tab and ctrl+shift+J (checkbox) `修复缺陷`
* [550](https://github.com/Vanessa219/vditor/issues/550) [Mermaid] State diagram rendering of multiple same node loops `修复缺陷`
Expand All @@ -78,10 +81,6 @@
* [543](https://github.com/Vanessa219/vditor/issues/543) SV 模式删除选择文本问题 `修复缺陷`
* [541](https://github.com/Vanessa219/vditor/issues/541) SV 模式列表和引用快捷键问题 `修复缺陷`
* [546](https://github.com/Vanessa219/vditor/issues/546) SV 模式丢失 headingID `修复缺陷`
* 添加 `options.upload.multiple`

### v3.3.4 / 2020-07-08

* [539](https://github.com/Vanessa219/vditor/pull/539) 即时渲染模式 setValue 后,没有及时渲染 Code 区域 `修复缺陷`
* [536](https://github.com/Vanessa219/vditor/issues/536) 文件上传检查后缀忽略大小写 `改进功能`
* [537](https://github.com/Vanessa219/vditor/issues/537) 添加 destroy 方法 `引入特新`
Expand Down Expand Up @@ -126,6 +125,7 @@
* `setTheme` 参数修改为 `theme: "dark" | "classic", contentTheme?: string, codeTheme?: string, contentThemePath?: string`
* 移除 `setSelection`
* 添加 `destory` 方法
* 添加 `options.upload.multiple`

### v3.2.12 / 2020-06-07

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vditor",
"version": "3.3.4",
"version": "3.3.5",
"description": "♏ An In-browser Markdown editor, support WYSIWYG, Instant Rendering (Typora-like) and Split View modes.",
"author": "Vanessa <[email protected]> (http://vanessa.b3log.org)",
"homepage": "https://hacpai.com/tag/vditor",
Expand Down
3 changes: 3 additions & 0 deletions src/assets/icons/zhihu.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions src/js/lute/lute.min.js

Large diffs are not rendered by default.

28 changes: 17 additions & 11 deletions src/ts/preview/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import mpWechatSVG from "../../assets/icons/mp-wechat.svg";
import zhihutSVG from "../../assets/icons/zhihu.svg";
import {i18n} from "../i18n/index";
import {abcRender} from "../markdown/abcRender";
import {chartRender} from "../markdown/chartRender";
Expand Down Expand Up @@ -33,7 +34,7 @@ export class Preview {
tempElement.className = "vditor-reset";
tempElement.appendChild(getSelection().getRangeAt(0).cloneContents());

this.copyToWechat(vditor, tempElement);
this.copyToX(vditor, tempElement);
event.preventDefault();
});

Expand All @@ -42,7 +43,8 @@ export class Preview {
actionElement.innerHTML = `<button class="vditor-preview__action--current" data-type="desktop">Desktop</button>
<button data-type="tablet">Tablet</button>
<button data-type="mobile">Mobile/Wechat</button>
<button data-type="mp-wechat" class="vditor-tooltipped vditor-tooltipped__w" aria-label="复制到公众号">${mpWechatSVG}</button>`;
<button data-type="mp-wechat" class="vditor-tooltipped vditor-tooltipped__w" aria-label="复制到公众号">${mpWechatSVG}</button>
<button data-type="zhihu" class="vditor-tooltipped vditor-tooltipped__w" aria-label="复制到知乎">${zhihutSVG}</button>`;
this.element.appendChild(actionElement);
this.element.appendChild(previewElement);

Expand All @@ -57,8 +59,8 @@ export class Preview {
return;
}

if (type === "mp-wechat") {
this.copyToWechat(vditor, this.element.lastElementChild.cloneNode(true) as HTMLElement);
if (type === "mp-wechat" || type === "zhihu") {
this.copyToX(vditor, this.element.lastElementChild.cloneNode(true) as HTMLElement, type);
return;
}

Expand Down Expand Up @@ -173,25 +175,29 @@ export class Preview {
mediaRender(vditor.preview.element.lastElementChild as HTMLElement);
}

private copyToWechat(vditor: IVditor, copyElement: HTMLElement) {
private copyToX(vditor: IVditor, copyElement: HTMLElement, type = "mp-wechat") {
// fix math render
copyElement.querySelectorAll(".katex-html .base").forEach((item: HTMLElement) => {
item.style.display = "initial";
});
if (type !== "zhihu") {
copyElement.querySelectorAll(".katex-html .base").forEach((item: HTMLElement) => {
item.style.display = "initial";
});
} else {
copyElement.querySelectorAll(".vditor-math").forEach((item: HTMLElement) => {
item.outerHTML = `<img class="Formula-image" data-eeimg="true" src="//www.zhihu.com/equation?tex=" alt="${item.getAttribute("data-math")}\\" style="display: block; margin: 0 auto; max-width: 100%;">`;
});
}
// 防止背景色被粘贴到公众号中
copyElement.style.backgroundColor = "#fff";
// 代码背景
copyElement.querySelectorAll("code").forEach((item) => {
item.style.backgroundImage = "none";
});
this.element.append(copyElement);

const range = copyElement.ownerDocument.createRange();
range.selectNode(copyElement);
setSelectionFocus(range);
document.execCommand("copy");

this.element.lastElementChild.remove();
vditor.tip.show("已复制,可到微信公众号平台进行粘贴");
vditor.tip.show(`已复制,可到${type === "zhihu" ? "知乎" : "微信公众号平台"}进行粘贴`);
}
}

0 comments on commit e6f07e6

Please sign in to comment.