diff --git a/data.json b/data.json index 80773cf..f8ecbe5 100644 --- a/data.json +++ b/data.json @@ -2,5 +2,5 @@ "strict_mode": false, "vaultDir": "D:\\iLanix\\Obsidian\nD:\\github\\ObsidianZY", "git_repo": "https://github.com/zigholding/ObsidianZ/tree/master\nhttps://gitee.com/zigholding/ObsidianZ/tree/master", - "wxmp_config": "" + "wxmp_config": "h1: ob 公众号标题 h1 样式\nh2: ob 公众号标题 h2 样式\nh3: ob 公众号标题 hx 样式\np code: ob 公众号行内代码样式\nli code: ob 公众号行内代码样式" } \ No newline at end of file diff --git a/src/commands.ts b/src/commands.ts index c83e223..75f5de0 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -221,13 +221,25 @@ const cmd_export_wxmp = (plugin:NoteSyncPlugin) => ({ hotkeys: [{ modifiers: ['Alt', 'Shift'], key: 'P' }], callback: async () => { if(!plugin.easyapi.cfile){return} + let htmls = []; let ctx = plugin.easyapi.ceditor.getSelection(); if(!ctx){ ctx = await plugin.app.vault.read(plugin.easyapi.cfile); + for(let section of plugin.easyapi.cmeta?.sections || []){ + if(section.type=='yaml'){ + continue + } + let sec = plugin.easyapi.editor.slice_by_position(ctx,section.position); + let html = plugin.wxmp.marked.marked(sec); + let rhtml = await plugin.wxmp.html_to_wxmp(html); + htmls.push(rhtml); + } + }else{ + let html = plugin.wxmp.marked.marked(ctx); + let rhtml = await plugin.wxmp.html_to_wxmp(html); + htmls.push(rhtml); } - let html = plugin.wxmp.marked.marked(ctx); - let rhtml = await plugin.wxmp.html_to_wxmp(html); - plugin.wxmp.copy_as_html(rhtml); + plugin.wxmp.copy_as_html(htmls); new Notice(`${plugin.strings.cmd_export_wxmp}: OK`,5000) } }); diff --git a/src/wxmp.ts b/src/wxmp.ts index b99d43f..1a9a1b0 100644 --- a/src/wxmp.ts +++ b/src/wxmp.ts @@ -21,6 +21,9 @@ export class Wxmp { for(let line of this.plugin.settings.wxmp_config.split('\n')){ let [key, value] = line.split(':'); if(!key || !value){continue} + key = key.trim(); + value = value.trim(); + if(!key || !value){continue} config[key] = value; } if(!config['h1']){ @@ -156,7 +159,6 @@ export class Wxmp { // 模板渲染,传入content let rendered = await this.plugin.easyapi.tpl.parse_templater(tpl, true, content); if (rendered.length > 0) { - // 只替换内容,不替换标签和属性 item.innerHTML = rendered[0]; } }