Skip to content

Commit

Permalink
fix err
Browse files Browse the repository at this point in the history
  • Loading branch information
Zacharia2 committed Feb 2, 2024
1 parent 53dd2c6 commit 9c34796
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 25 deletions.
11 changes: 11 additions & 0 deletions pyTestWIki/Callout.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
34 changes: 19 additions & 15 deletions pyTestWIki/shiraz_callout_syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,41 @@ 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))
}
}
// 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, `<<callout type:"${type}" title:"${title}" src:"${body}">>`);
console.log(page_content);
var page_content = page_content.replace(quotes_str_full, `<<callout type:"${type}" title:"${title}" src:"${body}">>\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);
4 changes: 2 additions & 2 deletions src/obsidian-vault/plugin.info
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 13 additions & 8 deletions src/obsidian-vault/syntax/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, `<<callout type:"${type}" title:"${title}" src:"${body}">>`);
var page_content = page_content.replace(quotes_str_full, `<<callout type:"${type}" title:"${title}" src:"${body}">>\n`);
}
return page_content
}
Expand Down

0 comments on commit 9c34796

Please sign in to comment.