mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
This commit is contained in:
parent
48933e62f3
commit
842dbb6863
3 changed files with 18 additions and 90 deletions
|
@ -529,34 +529,6 @@
|
||||||
.protyle-icons {
|
.protyle-icons {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
&[data-copy-to="mp-wechat"] {
|
|
||||||
input[type="checkbox"] {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
li {
|
|
||||||
&.protyle-task:not(.protyle-task--done) {
|
|
||||||
list-style-type: "▢";
|
|
||||||
}
|
|
||||||
|
|
||||||
&.protyle-task--done {
|
|
||||||
list-style-type: "☑︎";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pre {
|
|
||||||
margin: 16px 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 暗黑模式
|
|
||||||
section.b3-typography {
|
|
||||||
&[data-copy-to="mp-wechat"] {
|
|
||||||
background-color: var(--b3-theme-background);
|
|
||||||
padding: 10px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.protyle {
|
.protyle {
|
||||||
|
|
|
@ -11,9 +11,6 @@ import {loadAssets} from "../util/assets";
|
||||||
import {resetFloatDockSize} from "../layout/dock/util";
|
import {resetFloatDockSize} from "../layout/dock/util";
|
||||||
import {confirmDialog} from "../dialog/confirmDialog";
|
import {confirmDialog} from "../dialog/confirmDialog";
|
||||||
import {useShell} from "../util/pathName";
|
import {useShell} from "../util/pathName";
|
||||||
/// #if !MOBILE
|
|
||||||
import {getAllEditor} from "../layout/getAll";
|
|
||||||
/// #endif
|
|
||||||
|
|
||||||
export const appearance = {
|
export const appearance = {
|
||||||
element: undefined as Element,
|
element: undefined as Element,
|
||||||
|
@ -267,24 +264,6 @@ export const appearance = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// #if !MOBILE
|
|
||||||
// 外观模式或主题改变之后,重新加载所有将 CSS 变量替换为实际值的导出预览
|
|
||||||
if (data.mode !== window.siyuan.config.appearance.mode ||
|
|
||||||
(data.mode === window.siyuan.config.appearance.mode && (
|
|
||||||
(data.mode === 0 && window.siyuan.config.appearance.themeLight !== data.themeLight) ||
|
|
||||||
(data.mode === 1 && window.siyuan.config.appearance.themeDark !== data.themeDark))
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
getAllEditor().forEach(editor => {
|
|
||||||
if (editor.protyle.preview && !editor.protyle.preview.element.classList.contains("fn__none") &&
|
|
||||||
editor.protyle.preview.previewElement.dataset.fillCssVar === "true"
|
|
||||||
) {
|
|
||||||
editor.protyle.preview.render(editor.protyle);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/// #endif
|
|
||||||
|
|
||||||
window.siyuan.config.appearance = data;
|
window.siyuan.config.appearance = data;
|
||||||
if (appearance.element) {
|
if (appearance.element) {
|
||||||
const modeElement = appearance.element.querySelector("#mode") as HTMLSelectElement;
|
const modeElement = appearance.element.querySelector("#mode") as HTMLSelectElement;
|
||||||
|
|
|
@ -188,11 +188,6 @@ export class Preview {
|
||||||
}, response => {
|
}, response => {
|
||||||
const oldScrollTop = protyle.preview.previewElement.scrollTop;
|
const oldScrollTop = protyle.preview.previewElement.scrollTop;
|
||||||
protyle.preview.previewElement.innerHTML = response.data.html;
|
protyle.preview.previewElement.innerHTML = response.data.html;
|
||||||
if (response.data.fillCSSVar) {
|
|
||||||
protyle.preview.previewElement.dataset.fillCssVar = "true";
|
|
||||||
} else {
|
|
||||||
protyle.preview.previewElement.dataset.fillCssVar = "";
|
|
||||||
}
|
|
||||||
processRender(protyle.preview.previewElement);
|
processRender(protyle.preview.previewElement);
|
||||||
highlightRender(protyle.preview.previewElement);
|
highlightRender(protyle.preview.previewElement);
|
||||||
avRender(protyle.preview.previewElement, protyle);
|
avRender(protyle.preview.previewElement, protyle);
|
||||||
|
@ -223,7 +218,6 @@ export class Preview {
|
||||||
private async copyToX(copyElement: HTMLElement, protyle: IProtyle, type?: string) {
|
private async copyToX(copyElement: HTMLElement, protyle: IProtyle, type?: string) {
|
||||||
// fix math render
|
// fix math render
|
||||||
if (type === "mp-wechat") {
|
if (type === "mp-wechat") {
|
||||||
copyElement.dataset.copyTo = "mp-wechat";
|
|
||||||
this.link2online(copyElement);
|
this.link2online(copyElement);
|
||||||
copyElement.querySelectorAll(".katex-html .base").forEach((item: HTMLElement) => {
|
copyElement.querySelectorAll(".katex-html .base").forEach((item: HTMLElement) => {
|
||||||
item.style.display = "initial";
|
item.style.display = "initial";
|
||||||
|
@ -240,41 +234,18 @@ export class Preview {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
if (copyElement.dataset.fillCssVar === "true") {
|
// 处理任务列表(微信公众号不能显示input[type="checkbox"])
|
||||||
// 需要内联样式
|
copyElement.querySelectorAll("li.protyle-task").forEach((taskItem: HTMLElement) => {
|
||||||
// 微信公众号不能显示 input[type="checkbox"]
|
const checkbox = taskItem.querySelector('input[type="checkbox"]') as HTMLInputElement;
|
||||||
copyElement.querySelectorAll("li.protyle-task").forEach((taskItem: HTMLElement) => {
|
if (checkbox) {
|
||||||
const checkbox = taskItem.querySelector('input[type="checkbox"]') as HTMLInputElement;
|
checkbox.style.opacity = "0";
|
||||||
if (checkbox) {
|
if (checkbox.checked) {
|
||||||
checkbox.style.display = "none";
|
taskItem.style.setProperty("list-style-type", "'✅'", "important");
|
||||||
if (checkbox.checked) {
|
} else {
|
||||||
taskItem.style.setProperty("list-style-type", "'☑︎'");
|
taskItem.style.setProperty("list-style-type", "'▢'", "important");
|
||||||
} else {
|
|
||||||
taskItem.style.setProperty("list-style-type", "'▢'");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
// 代码块没有外间距
|
|
||||||
copyElement.querySelectorAll("pre").forEach((item: HTMLElement) => {
|
|
||||||
item.style.margin = "16px 0";
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
if (window.siyuan.config.appearance.mode === 0) {
|
|
||||||
// 明亮模式防止背景色被粘贴到公众号中
|
|
||||||
copyElement.style.backgroundColor = "#fff";
|
|
||||||
} else {
|
|
||||||
// 暗黑模式插入一层 section 设置背景色
|
|
||||||
const sectionElement = document.createElement("section");
|
|
||||||
sectionElement.innerHTML = copyElement.innerHTML;
|
|
||||||
copyElement.innerHTML = "";
|
|
||||||
copyElement.removeAttribute("style");
|
|
||||||
copyElement.appendChild(sectionElement);
|
|
||||||
// b3-typography 类名移动,否则选择器不匹配
|
|
||||||
sectionElement.classList.add("b3-typography");
|
|
||||||
copyElement.classList.remove("b3-typography");
|
|
||||||
sectionElement.dataset.copyTo = copyElement.dataset.copyTo;
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
if (typeof window.MathJax === "undefined") {
|
if (typeof window.MathJax === "undefined") {
|
||||||
window.MathJax = {
|
window.MathJax = {
|
||||||
svg: {
|
svg: {
|
||||||
|
@ -317,9 +288,15 @@ export class Preview {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 防止背景色被粘贴到公众号中
|
||||||
|
copyElement.style.backgroundColor = "#fff";
|
||||||
|
// 代码背景
|
||||||
|
copyElement.querySelectorAll("code").forEach((item) => {
|
||||||
|
item.style.backgroundImage = "none";
|
||||||
|
});
|
||||||
this.element.append(copyElement);
|
this.element.append(copyElement);
|
||||||
// 最后一个块是公式块时无法复制下来;section 元素后面还需要一个其他元素才能被复制
|
// 最后一个块是公式块时无法复制下来
|
||||||
copyElement.insertAdjacentHTML("beforeend", "<p style='background-color: transparent;'>‍</p>");
|
copyElement.insertAdjacentHTML("beforeend", "<p>‍</p>");
|
||||||
let cloneRange;
|
let cloneRange;
|
||||||
if (getSelection().rangeCount > 0) {
|
if (getSelection().rangeCount > 0) {
|
||||||
cloneRange = getSelection().getRangeAt(0).cloneRange();
|
cloneRange = getSelection().getRangeAt(0).cloneRange();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue