diff --git a/src/pdfblock/processor.ts b/src/pdfblock/processor.ts index b9d7a3b..4c2ec04 100644 --- a/src/pdfblock/processor.ts +++ b/src/pdfblock/processor.ts @@ -1,5 +1,5 @@ import * as pdfjs from "pdfjs-dist"; -import {FrontMatterCache, MarkdownPostProcessorContext, Notice} from "obsidian"; +import { FrontMatterCache, MarkdownPostProcessorContext } from "obsidian"; import SlideNotePlugin from '../main'; import { PDFBlockRenderer } from "./renderer"; @@ -11,6 +11,7 @@ export interface PDFBlockParameters { rotat: number; rect: Array; annot: string; + note: string; } export class PDFBlockProcessor { @@ -39,6 +40,7 @@ export class PDFBlockProcessor { const keywords = ["file", "page", "link", "scale", "rotat", "rect"]; const paramsRaw: { [k: string]: string } = {}; const annot: Array = []; + const note: Array = []; for (let i = 0; i < lines.length; i++) { const words = lines[i].trim().split(":") @@ -47,7 +49,10 @@ export class PDFBlockProcessor { paramsRaw[words[0]] = words[1].trim(); } else { - annot.push(lines[i].trim()); + if (lines[i].trim().startsWith("@")) + annot.push(lines[i].trim().slice(1)); + else + note.push(lines[i]); } } @@ -58,7 +63,8 @@ export class PDFBlockProcessor { scale: 0, rotat: 0, rect: [-1, -1, -1, -1], - annot: annot.join("\n") + annot: annot.join("\n"), + note: note.join("\n") }; // handle file diff --git a/src/pdfblock/renderer.ts b/src/pdfblock/renderer.ts index df63116..a245c3c 100644 --- a/src/pdfblock/renderer.ts +++ b/src/pdfblock/renderer.ts @@ -1,25 +1,25 @@ import * as pdfjs from "pdfjs-dist"; -import { MarkdownRenderChild } from "obsidian"; +import {MarkdownPreviewView, MarkdownRenderChild} from "obsidian"; import { PDFBlockParameters } from "./processor"; import { SlideNoteSettings } from "../settings"; export class PDFBlockRenderer extends MarkdownRenderChild { el: HTMLElement params: PDFBlockParameters - note: string + sourcePath: string settings: SlideNoteSettings public constructor( el: HTMLElement, params: PDFBlockParameters, - note: string, + sourcePath: string, settings: SlideNoteSettings ) { super(el); this.el = el; this.params = params; - this.note = note; + this.sourcePath = sourcePath; this.settings = settings; } @@ -43,12 +43,12 @@ export class PDFBlockRenderer extends MarkdownRenderChild { const arrayBuffer = await app.vault.adapter.readBinary(this.params.file); const buffer = Buffer.from(arrayBuffer); - if (!this.checkActiveFile(this.note)) + if (!this.checkActiveFile(this.sourcePath)) return; const document = await pdfjs.getDocument(buffer).promise; - if (!this.checkActiveFile(this.note)) + if (!this.checkActiveFile(this.sourcePath)) return; // page parameter as trigger for whole pdf, 0 = all pages @@ -62,7 +62,7 @@ export class PDFBlockRenderer extends MarkdownRenderChild { // Read pages for (const pageNumber of this.params.page) { - if (!this.checkActiveFile(this.note)) + if (!this.checkActiveFile(this.sourcePath)) return; const page = await document.getPage(pageNumber); @@ -81,7 +81,7 @@ export class PDFBlockRenderer extends MarkdownRenderChild { const canvas = host.createEl("canvas"); canvas.style.width = `${Math.floor(this.params.scale * 100)}%`; - if (!this.checkActiveFile(this.note)) + if (!this.checkActiveFile(this.sourcePath)) return; const context = canvas.getContext("2d"); @@ -108,7 +108,7 @@ export class PDFBlockRenderer extends MarkdownRenderChild { viewport: pageview, }; - if (!this.checkActiveFile(this.note)) + if (!this.checkActiveFile(this.sourcePath)) return; canvas.addEventListener("mouseup", (event)=> { @@ -136,7 +136,7 @@ export class PDFBlockRenderer extends MarkdownRenderChild { canvas.addEventListener("mouseleave", (event)=> { app.workspace.trigger("slidenote:mouseleave"); }); - + MarkdownPreviewView.renderMarkdown(this.params.note, host, this.sourcePath, this) await page.render(renderContext).promise.then( () => { if (this.params.annot != "" && this.settings.allow_annotations) {