diff --git a/main.ts b/main.ts index 57677e54..204d1fa9 100644 --- a/main.ts +++ b/main.ts @@ -30,7 +30,7 @@ export default class DigitalGarden extends Plugin { publishModal: PublishModal; async onload() { - this.appVersion = "2.9.2"; + this.appVersion = "2.9.3"; console.log("Initializing DigitalGarden plugin v" + this.appVersion); await this.loadSettings(); @@ -78,6 +78,7 @@ export default class DigitalGarden extends Plugin { return; } + new Notice("Publishing note..."); const publisher = new Publisher(vault, metadataCache, this.settings); const publishSuccessful = await publisher.publish(currentFile); diff --git a/manifest.json b/manifest.json index b17a8b06..d8e30342 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "digitalgarden", "name": "Digital Garden", - "version": "2.9.2", + "version": "2.9.3", "minAppVersion": "0.12.0", "description": "Publish your notes to a digital garden for others to enjoy.", "author": "Ole Eskild Steensen", diff --git a/src/Publisher.ts b/src/Publisher.ts index 1a2718ca..4b024716 100644 --- a/src/Publisher.ts +++ b/src/Publisher.ts @@ -255,11 +255,42 @@ export default class Publisher { async convertLinksToFullPath(text: string, filePath: string): Promise { let convertedText = text; - const links = this.metadataCache.getCache(filePath).links; - if (links && links.length) { - for (const link of links) { + + const linkedFileRegex = /\[\[(.*?)\]\]/g; + const linkedFileMatches = text.match(linkedFileRegex); + + const codeFenceRegex = /`(.*?)`/g; + const codeFences = text.match(codeFenceRegex); + + const codeBlockRegex = /```.*?\n[\s\S]+?```/g; + const codeBlocks = text.match(codeBlockRegex); + + const excaliDrawRegex = /:\[\[(\d*?,\d*?)\],.*?\]\]/g; + const excalidrawings = text.match(excaliDrawRegex); + + if (linkedFileMatches) { + for (const linkMatch of linkedFileMatches) { try { - const textInsideBrackets = link.original.substring(link.original.indexOf('[') + 2, link.original.indexOf(']')); + const insideCodeBlockIndex = codeBlocks ? codeBlocks.findIndex(codeBlock => codeBlock.includes(linkMatch)) : -1; + if(insideCodeBlockIndex>-1) { + codeBlocks.splice(insideCodeBlockIndex, 1); + continue; + } + + const insideCodeFenceIndex = codeFences ? codeFences.findIndex(codeFence => codeFence.includes(linkMatch)) : -1; + if(insideCodeFenceIndex>-1) { + codeFences.splice(insideCodeFenceIndex, 1); + continue; + } + + const excalidrawIndex = excalidrawings ? excalidrawings.findIndex(excalidraw => excalidraw.includes(linkMatch)) : -1; + if(excalidrawIndex>-1) { + excalidrawings.splice(excalidrawIndex, 1); + continue; + } + + + const textInsideBrackets = linkMatch.substring(linkMatch.indexOf('[') + 2,linkMatch.lastIndexOf(']')-1); let [linkedFileName, prettyName] = textInsideBrackets.split("|"); prettyName = prettyName || linkedFileName; @@ -274,11 +305,11 @@ export default class Publisher { const fullLinkedFilePath = getLinkpath(linkedFileName); const linkedFile = this.metadataCache.getFirstLinkpathDest(fullLinkedFilePath, filePath); if(!linkedFile){ - convertedText = convertedText.replace(link.original, `[[${linkedFileName}${headerPath}|${prettyName}]]`); + convertedText = convertedText.replace(linkMatch, `[[${linkedFileName}${headerPath}|${prettyName}]]`); } if (linkedFile?.extension === "md") { const extensionlessPath = linkedFile.path.substring(0, linkedFile.path.lastIndexOf('.')); - convertedText = convertedText.replace(link.original, `[[${extensionlessPath}${headerPath}|${prettyName}]]`); + convertedText = convertedText.replace(linkMatch, `[[${extensionlessPath}${headerPath}|${prettyName}]]`); } } catch(e){ console.log(e); diff --git a/versions.json b/versions.json index 9e8aafe8..eaaef218 100644 --- a/versions.json +++ b/versions.json @@ -1,4 +1,5 @@ { + "2.9.3": "0.12.0", "2.9.2": "0.12.0", "2.9.1": "0.12.0", "2.9.0": "0.12.0",