mirror of
https://github.com/zigholding/obsidian-notesync-plugin.git
synced 2026-07-22 05:43:30 +00:00
wxmp
This commit is contained in:
parent
09cb452eb7
commit
a4a820ff60
3 changed files with 19 additions and 5 deletions
|
|
@ -2,5 +2,5 @@
|
||||||
"strict_mode": false,
|
"strict_mode": false,
|
||||||
"vaultDir": "D:\\iLanix\\Obsidian\nD:\\github\\ObsidianZY",
|
"vaultDir": "D:\\iLanix\\Obsidian\nD:\\github\\ObsidianZY",
|
||||||
"git_repo": "https://github.com/zigholding/ObsidianZ/tree/master\nhttps://gitee.com/zigholding/ObsidianZ/tree/master",
|
"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 公众号行内代码样式"
|
||||||
}
|
}
|
||||||
|
|
@ -221,13 +221,25 @@ const cmd_export_wxmp = (plugin:NoteSyncPlugin) => ({
|
||||||
hotkeys: [{ modifiers: ['Alt', 'Shift'], key: 'P' }],
|
hotkeys: [{ modifiers: ['Alt', 'Shift'], key: 'P' }],
|
||||||
callback: async () => {
|
callback: async () => {
|
||||||
if(!plugin.easyapi.cfile){return}
|
if(!plugin.easyapi.cfile){return}
|
||||||
|
let htmls = [];
|
||||||
let ctx = plugin.easyapi.ceditor.getSelection();
|
let ctx = plugin.easyapi.ceditor.getSelection();
|
||||||
if(!ctx){
|
if(!ctx){
|
||||||
ctx = await plugin.app.vault.read(plugin.easyapi.cfile);
|
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);
|
plugin.wxmp.copy_as_html(htmls);
|
||||||
let rhtml = await plugin.wxmp.html_to_wxmp(html);
|
|
||||||
plugin.wxmp.copy_as_html(rhtml);
|
|
||||||
new Notice(`${plugin.strings.cmd_export_wxmp}: OK`,5000)
|
new Notice(`${plugin.strings.cmd_export_wxmp}: OK`,5000)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,9 @@ export class Wxmp {
|
||||||
for(let line of this.plugin.settings.wxmp_config.split('\n')){
|
for(let line of this.plugin.settings.wxmp_config.split('\n')){
|
||||||
let [key, value] = line.split(':');
|
let [key, value] = line.split(':');
|
||||||
if(!key || !value){continue}
|
if(!key || !value){continue}
|
||||||
|
key = key.trim();
|
||||||
|
value = value.trim();
|
||||||
|
if(!key || !value){continue}
|
||||||
config[key] = value;
|
config[key] = value;
|
||||||
}
|
}
|
||||||
if(!config['h1']){
|
if(!config['h1']){
|
||||||
|
|
@ -156,7 +159,6 @@ export class Wxmp {
|
||||||
// 模板渲染,传入content
|
// 模板渲染,传入content
|
||||||
let rendered = await this.plugin.easyapi.tpl.parse_templater(tpl, true, content);
|
let rendered = await this.plugin.easyapi.tpl.parse_templater(tpl, true, content);
|
||||||
if (rendered.length > 0) {
|
if (rendered.length > 0) {
|
||||||
// 只替换内容,不替换标签和属性
|
|
||||||
item.innerHTML = rendered[0];
|
item.innerHTML = rendered[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue