Skip to content

Commit

Permalink
Merge pull request #3 from trinidz/wikijs-callouts
Browse files Browse the repository at this point in the history
Wikijs callouts
  • Loading branch information
trinidz authored Jan 11, 2025
2 parents b4ce672 + 0db3ea4 commit ea9d568
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 5 deletions.
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ jobs:
gh release create "$tag" \
--title="$tag" \
--draft \
main.js manifest.json
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
80 changes: 79 additions & 1 deletion src/methods/publishPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ export const publishPost = async (view: MarkdownView, settings: SettingsProp) =>
locale: metaMatter?.locale || "en",
};

const content_filtered = (<DataProp>data).content

let content_reconfig = configCalloutContent((<DataProp>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")
Expand Down Expand Up @@ -137,3 +143,75 @@ const wikiPostExists = async (uuidTag: string, settings: SettingsProp) => {
}
return noteId;
}

const configCalloutContent = (content: string): string => {
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)

input_lines.forEach((element, i, localArr) => {
element += '\n'
output_lines[i] += '\n'
calloutTagLineNums.push(calloutTagType)

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
calloutTagType = -2

if(localArr.length - 1 == i ){
calloutTagLineNums[i] = i
}
}
}
} else if (calloutTagType == -2){
if ( localArr[i].search(/^ *>/i) != -1 ){
//console.log('Ind:' + i + ' Sub Tag: '+ element)
} else {
wikiMainTagIndex = i-1
calloutTagLineNums[obsidMainTagIndex] = wikiMainTagIndex

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
calloutTagLineNums.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("\noutput lines:\n ",output_lines)
//console.log('\nNewContent:\n ' + new_content)
return new_content
}
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit ea9d568

Please sign in to comment.