diff --git a/pyTestWIki/Callout.md b/pyTestWIki/Callout.md index 25f46ef..246e3ac 100644 --- a/pyTestWIki/Callout.md +++ b/pyTestWIki/Callout.md @@ -1,6 +1,17 @@ + +> [!Note] Beta vault - contributions are welcome! +> This sandbox vault is in beta! +> +> If you spot a typo or a mistake, feel free to submit a pull request [here](https://github.com/obsidianmd/obsidian-docs/tree/master/Sandbox). + + + + As of v0.14.0, Obsidian supports callout blocks, sometimes called "admonitions". Callout blocks are written as a blockquote, inspired by the "alert" syntax from Microsoft Docs. Callouts are also be supported natively on Obsidian Publish. +> 11Here's a callout block. +> It supports **markdown** and [[Internal link|wikilinks]]. > [!NOTE] Tiel > For compatibility reasons, if you're also using the Admonitions plugin, you should update it to at least v8.0.0 to avoid problems with the new callout system. diff --git a/pyTestWIki/shiraz_callout_syntax.js b/pyTestWIki/shiraz_callout_syntax.js index bef4427..3db59da 100644 --- a/pyTestWIki/shiraz_callout_syntax.js +++ b/pyTestWIki/shiraz_callout_syntax.js @@ -2,24 +2,27 @@ const fs = require('fs'); function shiraz_callout_syntax(page_content) { - const ob_pattern = /^(> .+\n?)+$/gm; + const quote_pattern = /^( {0,3}> ?(.+|[^\n]*)(?:\r?\n|$))+/mg; // 当前md文件中存在的链接列表。 - const callout_array = [...page_content.matchAll(ob_pattern)]; - for (const item in callout_array) { - var callout_str_full = callout_array[item][0]; - var callout_line = callout_str_full.split(">") - var head = callout_line.splice(0, 2).join("") - var body = callout_line.join("") + const quotes_array = [...page_content.matchAll(quote_pattern)]; + for (const item in quotes_array) { + var quotes_str_full = quotes_array[item][0]; + if (!quotes_str_full.includes("[!")) continue; + var callout_line = quotes_str_full.split(">") + var head = callout_line.slice(0, 2).join("") + var body = callout_line.slice(2).join("") var head_arr = [] - if (head.includes(']\n')) { + if (/]\r?\n/g.test(head)) { head = head.trim() head_arr.push(head) } else { head = head.trim() - if (head.includes('-')) { - head_arr = head.split("- ") + if (head.includes("]-")) { + head_arr.push(head.slice(0, head.indexOf("]-") + 1)) // 从]符号后开始 + head_arr.push(head.slice(head.indexOf("]-") + 3)) // 从空格后开始 } - if (!head.includes('-')) { + else { + // indexOf返回数组中第一次出现给定元素的下标,如果不存在则返回 -1。 head_arr.push(head.slice(0, head.indexOf(" ") + 1).trim()) head_arr.push(head.slice(head.indexOf(" ") + 1)) } @@ -27,12 +30,13 @@ function shiraz_callout_syntax(page_content) { // let title = head_arr.length == 2 ? head_arr[1].substring(0, head_arr[1].length - 1) : "" let type = head_arr[0].substring(2, head_arr[0].length - 1).toLowerCase() let title = head_arr.length == 2 ? head_arr[1] : "" - var page_content = page_content.replace(callout_str_full, `<>`); - console.log(page_content); + var page_content = page_content.replace(quotes_str_full, `<>\n`); } + return page_content } const str = fs.readFileSync('./pyTestWIki/Callout.md').toString(); -shiraz_callout_syntax(str) -console.log(str); + +console.log(shiraz_callout_syntax(str)); +// console.log(str); diff --git a/src/obsidian-vault/plugin.info b/src/obsidian-vault/plugin.info index 500ecf8..ef56af6 100644 --- a/src/obsidian-vault/plugin.info +++ b/src/obsidian-vault/plugin.info @@ -2,9 +2,9 @@ "title": "$:/plugins/whitefall/obsidian-vault", "name": "Obsidian Vault", "author": "whitefall", - "description": "从 Obsidian 笔记库导入 Markdown 文件到 TiddlyWiki", + "description": "拷贝 Obsidian 笔记库并导入到 TiddlyWiki", "plugin-type": "plugin", - "version": "0.1.6", + "version": "0.1.7", "dependents": ["$:/plugins/tiddlywiki/markdown","$:/plugins/kookma/shiraz-callout"], "core-version": ">=5.2.0", "list": "readme ui/Panel ui/settings" diff --git a/src/obsidian-vault/syntax/index.ts b/src/obsidian-vault/syntax/index.ts index 18dcd15..ef12503 100644 --- a/src/obsidian-vault/syntax/index.ts +++ b/src/obsidian-vault/syntax/index.ts @@ -186,33 +186,38 @@ function bold_wiki_syntax(page_content: string) { return page_content } +// /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/ +// https://github.com/markedjs/marked/blob/365e720585b34a6d93faad4e9082521714f7807f/src/rules.ts#L65C26-L65C65 +// function shiraz_callout_syntax(page_content: string) { - const quotes_pattern = /^(>\s.+\n?)+$/gm; + const quotes_pattern = /^( {0,3}> ?(.+|[^\n]*)(?:\r?\n|$))+/mg; // 当前md文件中存在的链接列表。 const quotes_array = [...page_content.matchAll(quotes_pattern)]; for (const item in quotes_array) { var quotes_str_full = quotes_array[item][0]; - var callout_line = quotes_str_full.split(">") + if (!quotes_str_full.includes("[!")) continue; + var callout_line = quotes_str_full.split(">"); var head = callout_line.slice(0, 2).join("") var body = callout_line.slice(2).join("") var head_arr: any[] = [] - if (head.includes(']\n')) { + if (/]\r?\n/g.test(head)) { head = head.trim() head_arr.push(head) } else { head = head.trim() - if (head.includes('-')) { - head_arr = head.split("- ") + if (head.includes("]-")) { + head_arr.push(head.slice(0, head.indexOf("]-") + 1)) // 从]符号后开始 + head_arr.push(head.slice(head.indexOf("]-") + 3)) // 从空格后开始 } - if (!head.includes('-')) { + else { + // indexOf返回数组中第一次出现给定元素的下标,如果不存在则返回 -1。 head_arr.push(head.slice(0, head.indexOf(" ") + 1).trim()) head_arr.push(head.slice(head.indexOf(" ") + 1)) } } - // let title = head_arr.length == 2 ? head_arr[1].substring(0, head_arr[1].length - 1) : "" let type = head_arr[0].substring(2, head_arr[0].length - 1).toLowerCase() let title = head_arr.length == 2 ? head_arr[1] : "" - var page_content = page_content.replace(quotes_str_full, `<>`); + var page_content = page_content.replace(quotes_str_full, `<>\n`); } return page_content }