Skip to content

Commit

Permalink
feat: support org mode syntax for images and web url #67
Browse files Browse the repository at this point in the history
  • Loading branch information
debanjandhar12 committed Jun 2, 2022
1 parent c29f41e commit 706e63c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/converter/Converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ async function processEmbeds(htmlFile: HTMLFile, format: string = "markdown"): P
});

resultContent = await safeReplaceAsync(resultContent, LOGSEQ_PAGE_REF_REGEXP, async (match, pageName) => { // Convert page refs
const isImage = /^.*\.(png|jpg|jpeg|bmp|tiff|gif|apng|svg|webp)$/i;
const isWebURL = /^(https?:(\/\/)?(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:(\/\/)?(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})$/i;
if(format == "org" && encodeURI(pageName).match(isImage)) {
console.log("Image found in org format:", pageName);
return `![](${pageName})`;
}
else if(format == "org" && encodeURI(pageName).match(isWebURL)) {
console.log("Web URL found in org format:", pageName);
return `${pageName}`;
}
return `<a href="logseq://graph/${encodeURIComponent(_.get(await logseq.App.getCurrentGraph(), 'name'))}?page=${encodeURIComponent(pageName)}" class="page-reference">${pageName}</a>`
});
resultContent = await safeReplaceAsync(resultContent, LOGSEQ_RENAMED_BLOCK_REF_REGEXP, async (match, aliasContent, blockUUID) => { // Convert page refs
Expand Down

0 comments on commit 706e63c

Please sign in to comment.