From 51e3b937d95c79f896989e8badf666f76d17e711 Mon Sep 17 00:00:00 2001 From: trinidz Date: Thu, 9 Jan 2025 17:23:27 +0000 Subject: [PATCH 1/5] init callout function --- src/methods/publishPost.ts | 65 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/methods/publishPost.ts b/src/methods/publishPost.ts index 060ddc5..d05e46e 100644 --- a/src/methods/publishPost.ts +++ b/src/methods/publishPost.ts @@ -137,3 +137,68 @@ const wikiPostExists = async (uuidTag: string, settings: SettingsProp) => { } return noteId; } + +const configCalloutContent = (content: string): string => { + const callouts_line_nums: number[] = [] + let searchType = -1 + const input_lines = content.split('\n') + const output_lines = content.split('\n') + let obsidMainTagIndex = 0 + let wikiMainTagIndex = 0 + + console.log("\ninput_lines:\n" + input_lines) + + input_lines.forEach((element, i, localArr) => { + element += '\n' + output_lines[i] += '\n' + callouts_line_nums.push(searchType) + + if (searchType == -1) { + var found = element.search(/^ {0,3}> ?\[\!info\][ ]*[\n]|^ {0,3}> ?\[\!warning\][ ]*[\n]|^ {0,3}> ?\[\!danger\][ ]*[\n]/i) + if (found != -1){ + if ( i == 0 || (i > 0 && localArr[i-1].search(/^ *>/i) == -1) ) { + //console.log('Ind:' + i + ' Main Tag: ' + element) + obsidMainTagIndex = i + searchType = -2 + + if(localArr.length - 1 == i ){ + callouts_line_nums[i] = i + } + } + } + } else if (searchType == -2){ + if ( localArr[i].search(/^ *>/i) != -1 ){ + //console.log('Ind:' + i + ' Sub Tag: '+ element) + } else { + wikiMainTagIndex = i-1 + callouts_line_nums[obsidMainTagIndex] = wikiMainTagIndex + + searchType = -1 + obsidMainTagIndex = 0 + wikiMainTagIndex = 0 + } + } + }); + + let captured_tag: string + let new_content:string + callouts_line_nums.forEach((element, indx)=>{ + if (element > 0) { + captured_tag = output_lines.splice(indx,1)[0] + output_lines.splice(element,0,captured_tag) + } + }) + + output_lines.forEach((ele, indx)=>{ + if(indx == 0) { + new_content = ele + } else { + new_content += ele + } + }) + + //console.log("CalloutNums: ",callouts_line_nums) + //console.log("\noutput lines:\n ",output_lines) + //console.log('\nNewContent:\n ' + new_content) + return new_content +} \ No newline at end of file From eaede110992e58f9ea2feb093d1d1e30a2cf9140 Mon Sep 17 00:00:00 2001 From: trinidz Date: Thu, 9 Jan 2025 17:27:43 +0000 Subject: [PATCH 2/5] basic callout convert working --- src/methods/publishPost.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/methods/publishPost.ts b/src/methods/publishPost.ts index d05e46e..82dc8a2 100644 --- a/src/methods/publishPost.ts +++ b/src/methods/publishPost.ts @@ -52,7 +52,13 @@ export const publishPost = async (view: MarkdownView, settings: SettingsProp) => locale: metaMatter?.locale || "en", }; - const content_filtered = (data).content + + let content_reconfig = configCalloutContent((data).content) + + const content_filtered = content_reconfig + .replace(/^ {0,3}> ?\[\!info\]/gmi,"> {.is-info}") + .replace(/^ {0,3}> ?\[\!warning\]/gmi,"> {.is-warning}") + .replace(/^ {0,3}> ?\[\!danger\]/gmi,"> {.is-danger}") .replace(/\\/g, "/") .replace(/\"/g, "'") .replace(/\n/g, "\\n") From 2a5bba9dd3e0c5cf27c87f978dced1d7018a4fc1 Mon Sep 17 00:00:00 2001 From: trinidz Date: Thu, 9 Jan 2025 17:43:37 +0000 Subject: [PATCH 3/5] remove draft option in workflow --- .github/workflows/release.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d24e796..f1a5a34 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,5 +34,4 @@ jobs: gh release create "$tag" \ --title="$tag" \ - --draft \ main.js manifest.json \ No newline at end of file From 3baf0a00da1ec57dcb7c1a6519d5e85805a75758 Mon Sep 17 00:00:00 2001 From: trinidz Date: Sat, 11 Jan 2025 19:27:25 +0000 Subject: [PATCH 4/5] versionon update and return if no callouts --- package.json | 2 +- src/methods/publishPost.ts | 33 ++++++++++++++++++++------------- versions.json | 3 ++- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 5f05878..018d1e0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-wikijs-publish", - "version": "0.0.4", + "version": "0.0.5", "description": "Obsidian plugin for easy publish to wikijs with a single click.", "main": "src/main.ts", "scripts": { diff --git a/src/methods/publishPost.ts b/src/methods/publishPost.ts index 82dc8a2..33f7e4d 100644 --- a/src/methods/publishPost.ts +++ b/src/methods/publishPost.ts @@ -145,51 +145,59 @@ const wikiPostExists = async (uuidTag: string, settings: SettingsProp) => { } const configCalloutContent = (content: string): string => { - const callouts_line_nums: number[] = [] - let searchType = -1 + const calloutTagLineNums: number[] = [] + let calloutTagType = -1 const input_lines = content.split('\n') const output_lines = content.split('\n') let obsidMainTagIndex = 0 let wikiMainTagIndex = 0 - console.log("\ninput_lines:\n" + input_lines) + //console.log("\ninput_lines:\n" + input_lines) input_lines.forEach((element, i, localArr) => { element += '\n' output_lines[i] += '\n' - callouts_line_nums.push(searchType) + calloutTagLineNums.push(calloutTagType) - if (searchType == -1) { + if (calloutTagType == -1) { var found = element.search(/^ {0,3}> ?\[\!info\][ ]*[\n]|^ {0,3}> ?\[\!warning\][ ]*[\n]|^ {0,3}> ?\[\!danger\][ ]*[\n]/i) if (found != -1){ if ( i == 0 || (i > 0 && localArr[i-1].search(/^ *>/i) == -1) ) { //console.log('Ind:' + i + ' Main Tag: ' + element) obsidMainTagIndex = i - searchType = -2 + calloutTagType = -2 if(localArr.length - 1 == i ){ - callouts_line_nums[i] = i + calloutTagLineNums[i] = i } } } - } else if (searchType == -2){ + } else if (calloutTagType == -2){ if ( localArr[i].search(/^ *>/i) != -1 ){ //console.log('Ind:' + i + ' Sub Tag: '+ element) } else { wikiMainTagIndex = i-1 - callouts_line_nums[obsidMainTagIndex] = wikiMainTagIndex + calloutTagLineNums[obsidMainTagIndex] = wikiMainTagIndex - searchType = -1 + calloutTagType = -1 obsidMainTagIndex = 0 wikiMainTagIndex = 0 } } }); + let calloutTagsExist = calloutTagLineNums.some((val)=>{ + return val >= 0 + }) + + if (!calloutTagsExist){ + return content + } + let captured_tag: string let new_content:string - callouts_line_nums.forEach((element, indx)=>{ - if (element > 0) { + calloutTagLineNums.forEach((element, indx)=>{ + if (element >= 0) { captured_tag = output_lines.splice(indx,1)[0] output_lines.splice(element,0,captured_tag) } @@ -203,7 +211,6 @@ const configCalloutContent = (content: string): string => { } }) - //console.log("CalloutNums: ",callouts_line_nums) //console.log("\noutput lines:\n ",output_lines) //console.log('\nNewContent:\n ' + new_content) return new_content diff --git a/versions.json b/versions.json index 6af091d..eb37450 100644 --- a/versions.json +++ b/versions.json @@ -3,5 +3,6 @@ "0.0.1": "0.12.0", "0.0.2": "0.12.0", "0.0.3": "0.12.0", - "0.0.4": "0.12.0" + "0.0.4": "0.12.0", + "0.0.5": "0.12.0" } From 0db3ea465d612f841d64e141aeb22e16e103c4fb Mon Sep 17 00:00:00 2001 From: trinidz Date: Sat, 11 Jan 2025 19:54:03 +0000 Subject: [PATCH 5/5] update manifest --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 3bec9dc..0285e43 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "send-to-wikijs", "name": "Send to Wikijs", - "version": "0.0.4", + "version": "0.0.5", "minAppVersion": "0.12.0", "description": "Send and publish notes to your wikijs with a single click", "author": "trinidz",