diff --git a/src/compiler/ExcalidrawCompiler.ts b/src/compiler/ExcalidrawCompiler.ts index 2ae89e95..61976cd3 100644 --- a/src/compiler/ExcalidrawCompiler.ts +++ b/src/compiler/ExcalidrawCompiler.ts @@ -1,6 +1,17 @@ -import { TFile, Vault } from "obsidian"; +import { Vault } from "obsidian"; import { excaliDrawBundle, excalidraw } from "../ui/suggest/constants"; import LZString from "lz-string"; +import { TCompilerStep } from "./GardenPageCompiler"; +import { PublishFile } from "../publisher/PublishFile"; + +interface IExcalidrawCompilerProps { + /**Includes excalidraw script bundle in compilation result */ + includeExcaliDrawJs: boolean; + /** Is appended to the drawing id */ + idAppendage?: string; + /** Includes frontmatter in compilation result */ + includeFrontMatter?: boolean; +} export class ExcalidrawCompiler { private readonly vault: Vault; @@ -8,49 +19,49 @@ export class ExcalidrawCompiler { constructor(vault: Vault) { this.vault = vault; } - async compileMarkdown( - { - file, - processedFrontmatter, - fileText, - }: { - file: TFile; - processedFrontmatter: string; - fileText: string; - }, - includeExcaliDrawJs: boolean, - idAppendage = "", - includeFrontMatter = true, - ): Promise { - if (!file.name.endsWith(".excalidraw.md")) return ""; - - const isCompressed = fileText.includes("```compressed-json"); - - const start = - fileText.indexOf(isCompressed ? "```compressed-json" : "```json") + - (isCompressed ? "```compressed-json" : "```json").length; - const end = fileText.lastIndexOf("```"); - - const excaliDrawJson = JSON.parse( - isCompressed - ? LZString.decompressFromBase64( - fileText.slice(start, end).replace(/[\n\r]/g, ""), - ) - : fileText.slice(start, end), - ); - - const drawingId = - file.name.split(" ").join("_").replace(".", "") + idAppendage; - let excaliDrawCode = ""; - - if (includeExcaliDrawJs) { - excaliDrawCode += excaliDrawBundle; - } - - excaliDrawCode += excalidraw(JSON.stringify(excaliDrawJson), drawingId); - - return `${ - includeFrontMatter ? processedFrontmatter : "" - }${excaliDrawCode}`; - } + compileMarkdown = + ({ + includeExcaliDrawJs, + idAppendage = "", + includeFrontMatter = true, + }: IExcalidrawCompilerProps): TCompilerStep => + (file: PublishFile) => + (fileText: string) => { + if (!file.file.name.endsWith(".excalidraw.md")) { + throw new Error("File is not an excalidraw file"); + } + + const isCompressed = fileText.includes("```compressed-json"); + const startString = isCompressed ? "```compressed-json" : "```json"; + + const start = fileText.indexOf(startString) + startString.length; + const end = fileText.lastIndexOf("```"); + + const excaliDrawJson = JSON.parse( + isCompressed + ? LZString.decompressFromBase64( + fileText.slice(start, end).replace(/[\n\r]/g, ""), + ) + : fileText.slice(start, end), + ); + + const drawingId = + file.file.name.split(" ").join("_").replace(".", "") + + idAppendage; + + let excaliDrawCode = ""; + + if (includeExcaliDrawJs) { + excaliDrawCode += excaliDrawBundle; + } + + excaliDrawCode += excalidraw( + JSON.stringify(excaliDrawJson), + drawingId, + ); + + return `${ + includeFrontMatter ? file.getCompiledFrontmatter() : "" + }${excaliDrawCode}`; + }; } diff --git a/src/compiler/FrontmatterCompiler.ts b/src/compiler/FrontmatterCompiler.ts index 7dfe9b6f..e0119fb1 100644 --- a/src/compiler/FrontmatterCompiler.ts +++ b/src/compiler/FrontmatterCompiler.ts @@ -42,13 +42,10 @@ export class FrontmatterCompiler { const frontmatter = metadataCache.getCache(file.path)?.frontmatter ?? {}; - return this.getProcessedFrontMatter(file, frontmatter); + return this.compile(file, frontmatter); } - getProcessedFrontMatter( - file: TFile, - frontmatter: FrontMatterCache, - ): string { + compile(file: TFile, frontmatter: FrontMatterCache): string { const fileFrontMatter = { ...frontmatter }; delete fileFrontMatter["position"]; diff --git a/src/compiler/GardenPageCompiler.ts b/src/compiler/GardenPageCompiler.ts index 20e08488..97b88d4d 100644 --- a/src/compiler/GardenPageCompiler.ts +++ b/src/compiler/GardenPageCompiler.ts @@ -18,7 +18,6 @@ import { getRewriteRules, sanitizePermalink, } from "../utils/utils"; -import { FrontmatterCompiler } from "./FrontmatterCompiler"; import { ExcalidrawCompiler } from "./ExcalidrawCompiler"; import { getAPI } from "obsidian-dataview"; import slugify from "@sindresorhus/slugify"; @@ -29,8 +28,10 @@ import { EXCALIDRAW_REGEX, FRONTMATTER_REGEX, BLOCKREF_REGEX, + TRANSCLUDED_SVG_REGEX, } from "../utils/regexes"; import Logger from "js-logger"; +import { PublishFile } from "../publisher/PublishFile"; export interface Asset { path: string; @@ -42,10 +43,15 @@ export interface Assets { export type TCompiledFile = [string, Assets]; +export type TCompilerStep = ( + publishFile: PublishFile, +) => + | ((partiallyCompiledContent: string) => Promise) + | ((partiallyCompiledContent: string) => string); + export class GardenPageCompiler { private readonly vault: Vault; private readonly settings: DigitalGardenSettings; - private frontMatterCompiler: FrontmatterCompiler; private excalidrawCompiler: ExcalidrawCompiler; private metadataCache: MetadataCache; private readonly getFilesMarkedForPublishing: Publisher["getFilesMarkedForPublishing"]; @@ -62,49 +68,54 @@ export class GardenPageCompiler { this.settings = settings; this.metadataCache = metadataCache; this.getFilesMarkedForPublishing = getFilesMarkedForPublishing; - this.frontMatterCompiler = new FrontmatterCompiler(settings); this.excalidrawCompiler = new ExcalidrawCompiler(vault); this.rewriteRules = getRewriteRules(this.settings.pathRewriteRules); } - async generateMarkdown(file: TFile): Promise { + async generateMarkdown(file: PublishFile): Promise { const assets: Assets = { images: [] }; - const processedFrontmatter = - this.frontMatterCompiler.getFrontMatterFromFile( - file, - this.metadataCache, - ); - - const fileText = await this.vault.cachedRead(file); + const vaultFileText = await file.cachedRead(); - if (file.name.endsWith(".excalidraw.md")) { + if (file.file.name.endsWith(".excalidraw.md")) { return [ - await this.excalidrawCompiler.compileMarkdown( - { file, processedFrontmatter, fileText }, - true, - ), + await this.excalidrawCompiler.compileMarkdown({ + includeExcaliDrawJs: true, + })(file)(vaultFileText), assets, ]; } - let text = await this.convertFrontMatter( - fileText, - processedFrontmatter, + // ORDER MATTERS! + const COMPILE_STEPS: TCompilerStep[] = [ + this.convertFrontMatter, + this.convertCustomFilters, + this.createBlockIDs, + this.createTranscludedText(0), + this.convertDataViews, + this.convertLinksToFullPath, + this.removeObsidianComments, + this.createSvgEmbeds, + ]; + + const compiledText = await COMPILE_STEPS.reduce( + async (previousStep, compilerStep) => { + const previousStepText = await previousStep; + + return compilerStep(file)(previousStepText); + }, + Promise.resolve(vaultFileText), + ); + + const text_and_images = await this.convertImageLinks( + compiledText, + file.getPath(), ); - text = await this.convertCustomFilters(text); - text = await this.createBlockIDs(text); - text = await this.createTranscludedText(text, file.path, 0); - text = await this.convertDataViews(text, file.path); - text = await this.convertLinksToFullPath(text, file.path); - text = await this.removeObsidianComments(text); - text = await this.createSvgEmbeds(text, file.path); - const text_and_images = await this.convertImageLinks(text, file.path); return [text_and_images[0], { images: text_and_images[1] }]; } - async convertCustomFilters(text: string) { + convertCustomFilters: TCompilerStep = () => (text) => { for (const filter of this.settings.customFilters) { try { text = text.replace( @@ -123,15 +134,15 @@ export class GardenPageCompiler { } return text; - } + }; - async createBlockIDs(text: string) { + createBlockIDs: TCompilerStep = () => (text: string) => { const block_pattern = / \^([\w\d-]+)/g; const complex_block_pattern = /\n\^([\w\d-]+)\n/g; text = text.replace( complex_block_pattern, - (match: string, $1: string) => { + (_match: string, $1: string) => { return `{ #${$1}}\n\n`; }, ); @@ -141,9 +152,9 @@ export class GardenPageCompiler { }); return text; - } + }; - async removeObsidianComments(text: string): Promise { + removeObsidianComments: TCompilerStep = () => (text) => { const obsidianCommentsRegex = /%%.+?%%/gms; const obsidianCommentsMatches = text.match(obsidianCommentsRegex); const codeBlocks = text.match(CODEBLOCK_REGEX) || []; @@ -175,20 +186,17 @@ export class GardenPageCompiler { } return text; - } + }; - async convertFrontMatter( - text: string, - frontmatter: string, - ): Promise { + convertFrontMatter: TCompilerStep = (file) => (text) => { const replaced = text.replace(FRONTMATTER_REGEX, (_match, _p1) => { - return frontmatter; + return file.getCompiledFrontmatter(); }); return replaced; - } + }; - async convertDataViews(text: string, path: string): Promise { + convertDataViews: TCompilerStep = (file) => async (text) => { let replacedText = text; const dataViewRegex = /```dataview\s(.+?)```/gms; const dvApi = getAPI(); @@ -234,7 +242,11 @@ export class GardenPageCompiler { try { const block = queryBlock[0]; const query = queryBlock[1]; - const markdown = await dvApi.tryQueryMarkdown(query, path); + + const markdown = await dvApi.tryQueryMarkdown( + query, + file.getPath(), + ); replacedText = replacedText.replace( block, @@ -258,7 +270,7 @@ export class GardenPageCompiler { const div = createEl("div"); const component = new Component(); - await dvApi.executeJs(query, div, component, path); + await dvApi.executeJs(query, div, component, file.getPath()); component.load(); replacedText = replacedText.replace(block, div.innerHTML); @@ -309,7 +321,7 @@ export class GardenPageCompiler { const div = createEl("div"); const component = new Component(); - await dvApi.executeJs(query, div, component, path); + await dvApi.executeJs(query, div, component, file.getPath()); component.load(); replacedText = replacedText.replace(code, div.innerHTML); @@ -325,9 +337,9 @@ export class GardenPageCompiler { } return replacedText; - } + }; - stripAwayCodeFencesAndFrontmatter(text: string): string { + stripAwayCodeFencesAndFrontmatter: TCompilerStep = () => (text) => { let textToBeProcessed = text; textToBeProcessed = textToBeProcessed.replace(EXCALIDRAW_REGEX, ""); textToBeProcessed = textToBeProcessed.replace(CODEBLOCK_REGEX, ""); @@ -336,15 +348,13 @@ export class GardenPageCompiler { textToBeProcessed = textToBeProcessed.replace(FRONTMATTER_REGEX, ""); return textToBeProcessed; - } + }; - async convertLinksToFullPath( - text: string, - filePath: string, - ): Promise { + convertLinksToFullPath: TCompilerStep = (file) => async (text) => { let convertedText = text; - const textToBeProcessed = this.stripAwayCodeFencesAndFrontmatter(text); + const textToBeProcessed = + await this.stripAwayCodeFencesAndFrontmatter(file)(text); const linkedFileRegex = /\[\[(.+?)\]\]/g; const linkedFileMatches = textToBeProcessed.match(linkedFileRegex); @@ -357,7 +367,7 @@ export class GardenPageCompiler { linkMatch.lastIndexOf("]") - 1, ); - let [linkedFileName, prettyName] = + let [linkedFileName, linkDisplayName] = textInsideBrackets.split("|"); if (linkedFileName.endsWith("\\")) { @@ -367,9 +377,10 @@ export class GardenPageCompiler { ); } - prettyName = prettyName || linkedFileName; + linkDisplayName = linkDisplayName || linkedFileName; let headerPath = ""; + // detect links to headers or blocks if (linkedFileName.includes("#")) { const headerSplit = linkedFileName.split("#"); linkedFileName = headerSplit[0]; @@ -382,17 +393,18 @@ export class GardenPageCompiler { const linkedFile = this.metadataCache.getFirstLinkpathDest( fullLinkedFilePath, - filePath, + file.getPath(), ); if (!linkedFile) { convertedText = convertedText.replace( linkMatch, - `[[${linkedFileName}${headerPath}\\|${prettyName}]]`, + `[[${linkedFileName}${headerPath}\\|${linkDisplayName}]]`, ); + continue; } - if (linkedFile?.extension === "md") { + if (linkedFile.extension === "md") { const extensionlessPath = linkedFile.path.substring( 0, linkedFile.path.lastIndexOf("."), @@ -400,7 +412,7 @@ export class GardenPageCompiler { convertedText = convertedText.replace( linkMatch, - `[[${extensionlessPath}${headerPath}\\|${prettyName}]]`, + `[[${extensionlessPath}${headerPath}\\|${linkDisplayName}]]`, ); } } catch (e) { @@ -411,29 +423,27 @@ export class GardenPageCompiler { } return convertedText; - } + }; + + createTranscludedText = + (currentDepth: number): TCompilerStep => + (file) => + async (text) => { + if (currentDepth >= 4) { + return text; + } - async createTranscludedText( - text: string, - filePath: string, - currentDepth: number, - ): Promise { - if (currentDepth >= 4) { - return text; - } + const { notes: publishedFiles } = + await this.getFilesMarkedForPublishing(); - const { notes: publishedFiles } = - await this.getFilesMarkedForPublishing(); - let transcludedText = text; - const transcludedRegex = /!\[\[(.+?)\]\]/g; - const transclusionMatches = text.match(transcludedRegex); - let numberOfExcaliDraws = 0; + let transcludedText = text; - if (transclusionMatches) { - for (let i = 0; i < transclusionMatches.length; i++) { - try { - const transclusionMatch = transclusionMatches[i]; + const transcludedRegex = /!\[\[(.+?)\]\]/g; + const transclusionMatches = text.match(transcludedRegex); + let numberOfExcaliDraws = 0; + for (const transclusionMatch of transclusionMatches ?? []) { + try { const [transclusionFileName, headerName] = transclusionMatch .substring( transclusionMatch.indexOf("[") + 2, @@ -446,37 +456,37 @@ export class GardenPageCompiler { const linkedFile = this.metadataCache.getFirstLinkpathDest( transclusionFilePath, - filePath, + file.getPath(), ); if (!linkedFile) { + console.error( + `can't find transcluded file ${transclusionFilePath}}`, + ); continue; } + + const publishLinkedFile = new PublishFile({ + file: linkedFile, + compiler: this, + metadataCache: this.metadataCache, + vault: this.vault, + settings: this.settings, + }); let sectionID = ""; if (linkedFile.name.endsWith(".excalidraw.md")) { - const firstDrawing = ++numberOfExcaliDraws === 1; + numberOfExcaliDraws++; + const isFirstDrawing = numberOfExcaliDraws === 1; - const processedFrontmatter = - this.frontMatterCompiler.getFrontMatterFromFile( - linkedFile, - this.metadataCache, - ); - - const fileText = - await this.vault.cachedRead(linkedFile); + const fileText = await publishLinkedFile.cachedRead(); const excaliDrawCode = - await this.excalidrawCompiler.compileMarkdown( - { - file: linkedFile, - processedFrontmatter, - fileText, - }, - firstDrawing, - `${numberOfExcaliDraws}`, - false, - ); + await this.excalidrawCompiler.compileMarkdown({ + includeExcaliDrawJs: isFirstDrawing, + idAppendage: `${numberOfExcaliDraws}`, + includeFrontMatter: false, + })(publishLinkedFile)(fileText); transcludedText = transcludedText.replace( transclusionMatch, @@ -553,7 +563,10 @@ export class GardenPageCompiler { fileText = fileText.replace(FRONTMATTER_REGEX, ""); // Apply custom filters to transclusion - fileText = await this.convertCustomFilters(fileText); + fileText = + await this.convertCustomFilters(publishLinkedFile)( + fileText, + ); // Remove block reference fileText = fileText.replace(BLOCKREF_REGEX, ""); @@ -596,10 +609,8 @@ export class GardenPageCompiler { if (fileText.match(transcludedRegex)) { fileText = await this.createTranscludedText( - fileText, - linkedFile.path, currentDepth + 1, - ); + )(publishLinkedFile)(fileText); } //This should be recursive up to a certain depth @@ -608,16 +619,16 @@ export class GardenPageCompiler { fileText, ); } - } catch { + } catch (error) { + console.error(error); continue; } } - } - return transcludedText; - } + return transcludedText; + }; - async createSvgEmbeds(text: string, filePath: string): Promise { + createSvgEmbeds: TCompilerStep = (file) => async (text) => { function setWidth(svgText: string, size: string): string { const parser = new DOMParser(); const svgDoc = parser.parseFromString(svgText, "image/svg+xml"); @@ -629,10 +640,7 @@ export class GardenPageCompiler { return svgSerializer.serializeToString(svgDoc); } - //![[image.svg]] - const transcludedSvgRegex = - /!\[\[(.*?)(\.(svg))\|(.*?)\]\]|!\[\[(.*?)(\.(svg))\]\]/g; - const transcludedSvgs = text.match(transcludedSvgRegex); + const transcludedSvgs = text.match(TRANSCLUDED_SVG_REGEX); if (transcludedSvgs) { for (const svg of transcludedSvgs) { @@ -644,7 +652,7 @@ export class GardenPageCompiler { const linkedFile = this.metadataCache.getFirstLinkpathDest( imagePath, - filePath, + file.getPath(), ); if (!linkedFile) { @@ -683,7 +691,7 @@ export class GardenPageCompiler { const linkedFile = this.metadataCache.getFirstLinkpathDest( imagePath, - filePath, + file.getPath(), ); if (!linkedFile) { @@ -703,9 +711,10 @@ export class GardenPageCompiler { } return text; - } + }; - async extractImageLinks(text: string, filePath: string): Promise { + extractImageLinks = async (file: PublishFile) => { + const text = await file.cachedRead(); const assets = []; //![[image.png]] @@ -728,7 +737,7 @@ export class GardenPageCompiler { const linkedFile = this.metadataCache.getFirstLinkpathDest( imagePath, - filePath, + file.getPath(), ); if (!linkedFile) { @@ -763,7 +772,7 @@ export class GardenPageCompiler { const linkedFile = this.metadataCache.getFirstLinkpathDest( decodedImagePath, - filePath, + file.getPath(), ); if (!linkedFile) { @@ -778,7 +787,7 @@ export class GardenPageCompiler { } return assets; - } + }; async convertImageLinks( text: string, diff --git a/src/dg-testVault/000 Home.md b/src/dg-testVault/000 Home.md index a0941f4e..8beca178 100644 --- a/src/dg-testVault/000 Home.md +++ b/src/dg-testVault/000 Home.md @@ -28,6 +28,6 @@ This test vault enables snapshot testing of the garden compilation! To generate This garden should have the following plugins -- [x] [[PE1 Embedded excalidraw]] +- [x] [[PE1 Transcluded excalidraw]] - [x] [[PD1 Dataview]] - [x] hot reload (reloads obsidian dev plugins on changes) \ No newline at end of file diff --git a/src/dg-testVault/E Embeds/Transclusions/files/T3 Second transclusion.md b/src/dg-testVault/E Embeds/Transclusions/files/T3 Second transclusion.md index 630e48c6..3a792e1a 100644 --- a/src/dg-testVault/E Embeds/Transclusions/files/T3 Second transclusion.md +++ b/src/dg-testVault/E Embeds/Transclusions/files/T3 Second transclusion.md @@ -6,7 +6,7 @@ I can go deeper! ![[T4 Deeper]] Bonus: -![[PE1 Embedded excalidraw]] +![[PE1 Transcluded excalidraw]] Bonus pic: diff --git a/src/dg-testVault/P Plugins/PE Excalidraw/PE1 Embedded excalidraw.md b/src/dg-testVault/P Plugins/PE Excalidraw/PE1 Transcluded excalidraw.md similarity index 100% rename from src/dg-testVault/P Plugins/PE Excalidraw/PE1 Embedded excalidraw.md rename to src/dg-testVault/P Plugins/PE Excalidraw/PE1 Transcluded excalidraw.md diff --git a/src/publisher/PublishFile.ts b/src/publisher/PublishFile.ts index 9c51bce9..fac70a53 100644 --- a/src/publisher/PublishFile.ts +++ b/src/publisher/PublishFile.ts @@ -8,7 +8,7 @@ import { TFrontmatter, } from "../compiler/FrontmatterCompiler"; import DigitalGardenSettings from "../models/settings"; -import { isPublishFrontmatterValid } from "./Validator"; +import { hasPublishFlag } from "./Validator"; interface IPublishFileProps { file: TFile; @@ -43,7 +43,7 @@ export class PublishFile { } async compile(): Promise { - const compiledFile = await this.compiler.generateMarkdown(this.file); + const compiledFile = await this.compiler.generateMarkdown(this); return new CompiledPublishFile( { @@ -57,14 +57,21 @@ export class PublishFile { ); } + // TODO: This doesn't work yet, but file should be able to tell it's type + getType(): "excalidraw" | "markdown" { + if (this.file.name.endsWith(".excalidraw")) { + return "excalidraw"; + } + + return "markdown"; + } + shouldPublish(): boolean { - return isPublishFrontmatterValid(this.frontmatter); + return hasPublishFlag(this.frontmatter); } async getImageLinks() { - const content = await this.cachedRead(); - - return this.compiler.extractImageLinks(content, this.file.path); + return this.compiler.extractImageLinks(this); } async cachedRead() { @@ -76,13 +83,13 @@ export class PublishFile { } getPath = () => this.file.path; - getProcessedFrontmatter() { + getCompiledFrontmatter() { const frontmatterCompiler = new FrontmatterCompiler(this.settings); const metadata = this.metadataCache.getCache(this.file.path)?.frontmatter ?? {}; - return frontmatterCompiler.getProcessedFrontMatter(this.file, metadata); + return frontmatterCompiler.compile(this.file, metadata); } } diff --git a/src/test/snapshot/generateGardenSnapshot.ts b/src/test/snapshot/generateGardenSnapshot.ts index 6f3866b1..06da3ae3 100644 --- a/src/test/snapshot/generateGardenSnapshot.ts +++ b/src/test/snapshot/generateGardenSnapshot.ts @@ -31,9 +31,8 @@ export const generateGardenSnapshot = async ( fileString += `${file.getPath()}\n`; fileString += "==========\n"; - const [content, assets] = await publisher.compiler.generateMarkdown( - file.file, - ); + const [content, assets] = + await publisher.compiler.generateMarkdown(file); assets.images.map((image) => assetPaths.add(image.path)); fileString += `${content}\n`; diff --git a/src/test/snapshot/snapshot.md b/src/test/snapshot/snapshot.md index 56eaa578..111692a7 100644 --- a/src/test/snapshot/snapshot.md +++ b/src/test/snapshot/snapshot.md @@ -46,10 +46,10 @@ This means this file should be in the root directory :) This subfolder also contains path rewrite testing! ========== -P Plugins/PE Excalidraw/PE1 Embedded excalidraw.md +P Plugins/PE Excalidraw/PE1 Transcluded excalidraw.md ========== --- -{"dg-publish":true,"permalink":"/p-plugins/pe-excalidraw/pe-1-embedded-excalidraw/"} +{"dg-publish":true,"permalink":"/p-plugins/pe-excalidraw/pe-1-transcluded-excalidraw/"} --- @@ -64,7 +64,7 @@ P Plugins/PD Dataview/PD1 Dataview.md I'm a list of all files in this folder: - [[P Plugins/PD Dataview/PD1 Dataview\|PD1 Dataview]] -- [[P Plugins/PE Excalidraw/PE1 Embedded excalidraw\|PE1 Embedded excalidraw]] +- [[P Plugins/PE Excalidraw/PE1 Transcluded excalidraw\|PE1 Transcluded excalidraw]] { .block-language-dataview} @@ -204,7 +204,7 @@ This is as far as we can go! Or is it??? Bonus: -
+
@@ -374,7 +374,7 @@ This test vault enables snapshot testing of the garden compilation! To generate This garden should have the following plugins -- [x] [[P Plugins/PE Excalidraw/PE1 Embedded excalidraw\|PE1 Embedded excalidraw]] +- [x] [[P Plugins/PE Excalidraw/PE1 Transcluded excalidraw\|PE1 Transcluded excalidraw]] - [x] [[P Plugins/PD Dataview/PD1 Dataview\|PD1 Dataview]] - [x] hot reload (reloads obsidian dev plugins on changes) ========== diff --git a/src/ui/PublishModal.ts b/src/ui/PublishModal.ts index 391adceb..0eb0da96 100644 --- a/src/ui/PublishModal.ts +++ b/src/ui/PublishModal.ts @@ -6,6 +6,7 @@ import PublicationCenter from "./PublicationCenter.svelte"; import DiffView from "./DiffView.svelte"; import DigitalGardenSiteManager from "src/publisher/DigitalGardenSiteManager"; import * as Diff from "diff"; +import { PublishFile } from "../publisher/PublishFile"; export class PublishModal { modal: Modal; @@ -52,9 +53,20 @@ export class PublishModal { await this.siteManager.getNoteContent(notePath); const localFile = this.vault.getAbstractFileByPath(notePath); + const localPublishFile = new PublishFile({ + file: localFile as TFile, + vault: this.vault, + compiler: this.publisher.compiler, + metadataCache: this.publisher.metadataCache, + settings: this.settings, + }); + if (localFile instanceof TFile) { const [localContent, _] = - await this.publisher.compiler.generateMarkdown(localFile); + await this.publisher.compiler.generateMarkdown( + localPublishFile, + ); + const diff = Diff.diffLines(remoteContent, localContent); let diffView: DiffView | undefined; const diffModal = new Modal(this.modal.app); diff --git a/src/utils/regexes.ts b/src/utils/regexes.ts index 11cec015..c9fad54a 100644 --- a/src/utils/regexes.ts +++ b/src/utils/regexes.ts @@ -2,5 +2,10 @@ export const FRONTMATTER_REGEX = /^\s*?---\n([\s\S]*?)\n---/g; export const BLOCKREF_REGEX = /(\^\w+(\n|$))/g; export const CODE_FENCE_REGEX = /`(.*?)`/g; + export const CODEBLOCK_REGEX = /```.*?\n[\s\S]+?```/g; + export const EXCALIDRAW_REGEX = /:\[\[(\d*?,\d*?)\],.*?\]\]/g; + +export const TRANSCLUDED_SVG_REGEX = + /!\[\[(.*?)(\.(svg))\|(.*?)\]\]|!\[\[(.*?)(\.(svg))\]\]/g;