diff --git a/src/obsidian/obsidianUtils.ts b/src/obsidian/obsidianUtils.ts index 42d4890..352455a 100644 --- a/src/obsidian/obsidianUtils.ts +++ b/src/obsidian/obsidianUtils.ts @@ -37,7 +37,7 @@ export class ObsidianUtils implements MediaCollector { private images = new Set(); private isCollecting = false; - private yamlRegex = /^---.*?---\n(.*?)($|---)/s; + private yamlRegex = /^(---\n[\s\S]*?\n---\n)/; constructor(app: App, settings: SlidesExtendedSettings) { this.app = app; @@ -229,13 +229,15 @@ export class ObsidianUtils implements MediaCollector { }); if (header === null) { - if (this.yamlRegex.test(fileContent)) { - return this.yamlRegex.exec(fileContent)[1]; + const match = this.yamlRegex.exec(fileContent); + if (match) { + return fileContent.slice(match[0].length); } return fileContent; } const cache = this.app.metadataCache.getFileCache(tfile); const resolved = resolveSubpath(cache, header); + console.log("parseFile, cache, resolved", cache, resolved); if (resolved && resolved.start && resolved.start.line != null) { if (resolved.end && resolved.end.line != null) { @@ -259,12 +261,6 @@ export class ObsidianUtils implements MediaCollector { } async fetchRemoteMarkdown(markdown: string): Promise { - const stackTrace = Error().stack; - console.log( - "fetchRemoteMarkdown", - markdown.contains("file://"), - stackTrace, - ); const wikilinkFileRegex = /!\[\[(file:.+?\.md)(\|[^\]]+)?\]\]/gi; const fileUrlRegex = /(!\[[^\]]*?\]\()(file:.+?\.md(?:#.+?)?)(\))/i; @@ -275,7 +271,6 @@ export class ObsidianUtils implements MediaCollector { const url = new URL(filePath); return `![${alias}](${url})`; }); - console.log(markdown); // Replace markdown links with markdown content if (fileUrlRegex.test(markdown)) { diff --git a/src/obsidian/processors/multipleFileProcessor.ts b/src/obsidian/processors/multipleFileProcessor.ts index e4b1b45..82b08a9 100644 --- a/src/obsidian/processors/multipleFileProcessor.ts +++ b/src/obsidian/processors/multipleFileProcessor.ts @@ -5,9 +5,10 @@ export class MultipleFileProcessor { private utils: ObsidianUtils; private regex = /!\[\[(.*?)(\|[^\]]*?)?\]\]/g; - private excalidrawRegex = /(.*\.excalidraw)/i; private markdownRegex = /!\[.*?\]\((.*?\.md)\)/g; + private excalidrawRegex = /(.*\.excalidraw)/i; + private wikilinkFileRegex = /\[\[(file:.+?)(\|[^\]]+)?\]\]/gi; private fileUrlRegex = /(\[[^\]]*?\]\()(file:.+?)((?: ".*?")?\))/gi; @@ -69,7 +70,6 @@ export class MultipleFileProcessor { } const fileName = this.getMarkdownFile(link.replace("%20", " ")); - if (fileName === null) { return matched; } @@ -79,10 +79,10 @@ export class MultipleFileProcessor { return matched; } - if (comment.length > 0) { - return this.process(content + comment); - } - return this.process(content); + const result = `\n +${this.process(content + comment).trim()} +\n`; + return result; }); } diff --git a/src/reveal/revealPreviewView.ts b/src/reveal/revealPreviewView.ts index 9875453..047c72e 100644 --- a/src/reveal/revealPreviewView.ts +++ b/src/reveal/revealPreviewView.ts @@ -94,8 +94,11 @@ export class RevealPreviewView extends ItemView { const view = this.app.workspace.getActiveViewOfType(MarkdownView); if (view?.file.name.includes(filename)) { const line = this.getTargetLine(url, view.data); - view.editor.setCursor(view.editor.lastLine()); - view.editor.setCursor({ line: line, ch: 0 }); + // line will be undefined for embedded content + if (line) { + view.editor.setCursor(view.editor.lastLine()); + view.editor.setCursor({ line: line, ch: 0 }); + } } } @@ -131,7 +134,6 @@ export class RevealPreviewView extends ItemView { break; } } - if (resultKey) { const keys = resultKey.split(","); return [Number.parseInt(keys[0]), Number.parseInt(keys[1])];