Skip to content

Commit 4e5863e

Browse files
Vanessa219leolee9086
authored andcommitted
1 parent fe2d58e commit 4e5863e

3 files changed

Lines changed: 18 additions & 90 deletions

File tree

app/src/assets/scss/component/_typography.scss

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -529,34 +529,6 @@
529529
.protyle-icons {
530530
display: none;
531531
}
532-
533-
&[data-copy-to="mp-wechat"] {
534-
input[type="checkbox"] {
535-
display: none;
536-
}
537-
538-
li {
539-
&.protyle-task:not(.protyle-task--done) {
540-
list-style-type: "";
541-
}
542-
543-
&.protyle-task--done {
544-
list-style-type: "☑︎";
545-
}
546-
}
547-
548-
pre {
549-
margin: 16px 0;
550-
}
551-
}
552-
}
553-
554-
// 暗黑模式
555-
section.b3-typography {
556-
&[data-copy-to="mp-wechat"] {
557-
background-color: var(--b3-theme-background);
558-
padding: 10px;
559-
}
560532
}
561533

562534
.protyle {

app/src/config/appearance.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ import {loadAssets} from "../util/assets";
1111
import {resetFloatDockSize} from "../layout/dock/util";
1212
import {confirmDialog} from "../dialog/confirmDialog";
1313
import {useShell} from "../util/pathName";
14-
/// #if !MOBILE
15-
import {getAllEditor} from "../layout/getAll";
16-
/// #endif
1714

1815
export const appearance = {
1916
element: undefined as Element,
@@ -267,24 +264,6 @@ export const appearance = {
267264
return;
268265
}
269266

270-
// #if !MOBILE
271-
// 外观模式或主题改变之后,重新加载所有将 CSS 变量替换为实际值的导出预览
272-
if (data.mode !== window.siyuan.config.appearance.mode ||
273-
(data.mode === window.siyuan.config.appearance.mode && (
274-
(data.mode === 0 && window.siyuan.config.appearance.themeLight !== data.themeLight) ||
275-
(data.mode === 1 && window.siyuan.config.appearance.themeDark !== data.themeDark))
276-
)
277-
) {
278-
getAllEditor().forEach(editor => {
279-
if (editor.protyle.preview && !editor.protyle.preview.element.classList.contains("fn__none") &&
280-
editor.protyle.preview.previewElement.dataset.fillCssVar === "true"
281-
) {
282-
editor.protyle.preview.render(editor.protyle);
283-
}
284-
});
285-
}
286-
/// #endif
287-
288267
window.siyuan.config.appearance = data;
289268
if (appearance.element) {
290269
const modeElement = appearance.element.querySelector("#mode") as HTMLSelectElement;

app/src/protyle/preview/index.ts

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,6 @@ export class Preview {
188188
}, response => {
189189
const oldScrollTop = protyle.preview.previewElement.scrollTop;
190190
protyle.preview.previewElement.innerHTML = response.data.html;
191-
if (response.data.fillCSSVar) {
192-
protyle.preview.previewElement.dataset.fillCssVar = "true";
193-
} else {
194-
protyle.preview.previewElement.dataset.fillCssVar = "";
195-
}
196191
processRender(protyle.preview.previewElement);
197192
highlightRender(protyle.preview.previewElement);
198193
avRender(protyle.preview.previewElement, protyle);
@@ -223,7 +218,6 @@ export class Preview {
223218
private async copyToX(copyElement: HTMLElement, protyle: IProtyle, type?: string) {
224219
// fix math render
225220
if (type === "mp-wechat") {
226-
copyElement.dataset.copyTo = "mp-wechat";
227221
this.link2online(copyElement);
228222
copyElement.querySelectorAll(".katex-html .base").forEach((item: HTMLElement) => {
229223
item.style.display = "initial";
@@ -240,41 +234,18 @@ export class Preview {
240234
}
241235
});
242236
});
243-
if (copyElement.dataset.fillCssVar === "true") {
244-
// 需要内联样式
245-
// 微信公众号不能显示 input[type="checkbox"]
246-
copyElement.querySelectorAll("li.protyle-task").forEach((taskItem: HTMLElement) => {
247-
const checkbox = taskItem.querySelector('input[type="checkbox"]') as HTMLInputElement;
248-
if (checkbox) {
249-
checkbox.style.display = "none";
250-
if (checkbox.checked) {
251-
taskItem.style.setProperty("list-style-type", "'☑︎'");
252-
} else {
253-
taskItem.style.setProperty("list-style-type", "'▢'");
254-
}
237+
// 处理任务列表(微信公众号不能显示input[type="checkbox"])
238+
copyElement.querySelectorAll("li.protyle-task").forEach((taskItem: HTMLElement) => {
239+
const checkbox = taskItem.querySelector('input[type="checkbox"]') as HTMLInputElement;
240+
if (checkbox) {
241+
checkbox.style.opacity = "0";
242+
if (checkbox.checked) {
243+
taskItem.style.setProperty("list-style-type", "'✅'", "important");
244+
} else {
245+
taskItem.style.setProperty("list-style-type", "'▢'", "important");
255246
}
256-
});
257-
// 代码块没有外间距
258-
copyElement.querySelectorAll("pre").forEach((item: HTMLElement) => {
259-
item.style.margin = "16px 0";
260-
});
261-
} else {
262-
if (window.siyuan.config.appearance.mode === 0) {
263-
// 明亮模式防止背景色被粘贴到公众号中
264-
copyElement.style.backgroundColor = "#fff";
265-
} else {
266-
// 暗黑模式插入一层 section 设置背景色
267-
const sectionElement = document.createElement("section");
268-
sectionElement.innerHTML = copyElement.innerHTML;
269-
copyElement.innerHTML = "";
270-
copyElement.removeAttribute("style");
271-
copyElement.appendChild(sectionElement);
272-
// b3-typography 类名移动,否则选择器不匹配
273-
sectionElement.classList.add("b3-typography");
274-
copyElement.classList.remove("b3-typography");
275-
sectionElement.dataset.copyTo = copyElement.dataset.copyTo;
276247
}
277-
}
248+
});
278249
if (typeof window.MathJax === "undefined") {
279250
window.MathJax = {
280251
svg: {
@@ -317,9 +288,15 @@ export class Preview {
317288
return;
318289
}
319290

291+
// 防止背景色被粘贴到公众号中
292+
copyElement.style.backgroundColor = "#fff";
293+
// 代码背景
294+
copyElement.querySelectorAll("code").forEach((item) => {
295+
item.style.backgroundImage = "none";
296+
});
320297
this.element.append(copyElement);
321-
// 最后一个块是公式块时无法复制下来;section 元素后面还需要一个其他元素才能被复制
322-
copyElement.insertAdjacentHTML("beforeend", "<p style='background-color: transparent;'>&zwj;</p>");
298+
// 最后一个块是公式块时无法复制下来
299+
copyElement.insertAdjacentHTML("beforeend", "<p>&zwj;</p>");
323300
let cloneRange;
324301
if (getSelection().rangeCount > 0) {
325302
cloneRange = getSelection().getRangeAt(0).cloneRange();

0 commit comments

Comments
 (0)