@@ -350,11 +350,6 @@ chrome.runtime.onStartup.addListener(() => {
350350 initDynamicRules ( )
351351} )
352352
353- // 点击扩展图标时打开 md.doocs.org
354- chrome . action . onClicked . addListener ( ( ) => {
355- chrome . tabs . create ( { url : 'https://md.doocs.org' } )
356- } )
357-
358353// 当前同步任务的 Tab Group ID
359354let currentSyncGroupId = null
360355// 存储平台用户信息
@@ -1088,8 +1083,11 @@ async function syncToPlatform(platformId, content) {
10881083 html = html . replace ( / ^ > ( .+ ) $ / gm, '<blockquote>$1</blockquote>' )
10891084
10901085 // 处理水平分割线
1091- html = html . replace ( / ^ - - - $ / gm, '<hr />' )
1092- html = html . replace ( / ^ \* \* \* $ / gm, '<hr />' )
1086+ // 注意: X Articles 忽略 <hr> 标签,需要通过 Insert > Divider 菜单插入
1087+ // 自动同步无法使用菜单,这里保留 hr 但用户可能需要手动调整
1088+ // 或者可以考虑用视觉分隔符如 --- 文本替代
1089+ html = html . replace ( / ^ - - - $ / gm, '<p>---</p>' )
1090+ html = html . replace ( / ^ \* \* \* $ / gm, '<p>***</p>' )
10931091
10941092 // 处理图片
10951093 html = html . replace ( / ! \[ ( [ ^ \] ] * ) \] \( ( [ ^ ) ] + ) \) / g, '<img src="$2" alt="$1" style="max-width: 100%;" />' )
@@ -1104,7 +1102,8 @@ async function syncToPlatform(platformId, content) {
11041102
11051103 // ========== 第三阶段:恢复保护的内容 ==========
11061104
1107- // 恢复代码块(使用样式化的 pre/code)
1105+ // 恢复代码块 - X Articles 不支持 <pre><code>,转换为 blockquote
1106+ // 参考 x-article-publisher skill 的实现
11081107 codeBlocks . forEach ( ( block , index ) => {
11091108 const escapedCode = block . code
11101109 . replace ( / & / g, '&' )
@@ -1113,19 +1112,25 @@ async function syncToPlatform(platformId, content) {
11131112 . replace ( / " / g, '"' )
11141113 . replace ( / ' / g, ''' )
11151114
1116- const langLabel = block . lang ? `<div style="background: #e1e4e8; padding: 4px 12px; font-size: 12px; color: #586069; border-radius: 6px 6px 0 0;">${ block . lang } </div>` : ''
1117- const codeHtml = `<div style="margin: 16px 0;">${ langLabel } <pre style="background: #f6f8fa; padding: 16px; border-radius: ${ block . lang ? '0 0 6px 6px' : '6px' } ; overflow-x: auto; font-family: 'SF Mono', Consolas, 'Liberation Mono', Menlo, monospace; font-size: 14px; line-height: 1.45; margin: 0; white-space: pre-wrap; word-wrap: break-word;"><code>${ escapedCode } </code></pre></div>`
1115+ // 将代码行用 <br> 连接,包装在 blockquote 中
1116+ // X Articles 原生支持 blockquote,这是最可靠的代码块显示方式
1117+ const lines = escapedCode . split ( '\n' ) . filter ( line => line . trim ( ) )
1118+ const formattedCode = lines . join ( '<br>' )
1119+ const langPrefix = block . lang ? `<strong>${ block . lang } </strong><br>` : ''
1120+ const codeHtml = `<blockquote>${ langPrefix } ${ formattedCode } </blockquote>`
11181121
11191122 html = html . replace ( `__CODE_BLOCK_${ index } __` , codeHtml )
11201123 } )
11211124
1122- // 恢复行内代码
1125+ // 恢复行内代码 - X Articles 对 inline style 支持有限
1126+ // 使用简单的 <code> 标签,依赖平台默认样式
11231127 inlineCodes . forEach ( ( code , index ) => {
11241128 const escapedCode = code
11251129 . replace ( / & / g, '&' )
11261130 . replace ( / < / g, '<' )
11271131 . replace ( / > / g, '>' )
1128- const codeHtml = `<code style="background: #f6f8fa; padding: 2px 6px; border-radius: 3px; font-family: 'SF Mono', Consolas, monospace; font-size: 0.9em;">${ escapedCode } </code>`
1132+ // 简化为纯 code 标签,X Articles 会应用默认样式
1133+ const codeHtml = `<code>${ escapedCode } </code>`
11291134
11301135 html = html . replace ( `__INLINE_CODE_${ index } __` , codeHtml )
11311136 } )
0 commit comments