@@ -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;' >‍</p>" ) ;
298+ // 最后一个块是公式块时无法复制下来
299+ copyElement . insertAdjacentHTML ( "beforeend" , "<p>‍</p>" ) ;
323300 let cloneRange ;
324301 if ( getSelection ( ) . rangeCount > 0 ) {
325302 cloneRange = getSelection ( ) . getRangeAt ( 0 ) . cloneRange ( ) ;
0 commit comments