Skip to content

Commit

Permalink
Merge pull request #17 from wxxedu/master
Browse files Browse the repository at this point in the history
Added support for relative path
  • Loading branch information
MSzturc authored Jun 19, 2022
2 parents 2d8e011 + c1385ef commit 933810c
Show file tree
Hide file tree
Showing 2 changed files with 558 additions and 562 deletions.
14 changes: 10 additions & 4 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin } from "obsidian";
import { Plugin, TFile } from "obsidian";
import { BetterPdfSettings, BetterPdfSettingsTab } from "./settings";
import * as pdfjs from "pdfjs-dist";
import * as worker from "pdfjs-dist/build/pdf.worker.entry.js";
Expand All @@ -25,8 +25,7 @@ export default class BetterPDFPlugin extends Plugin {

pdfjs.GlobalWorkerOptions.workerSrc = worker;

this.registerMarkdownCodeBlockProcessor("pdf", async (src, el) => {

this.registerMarkdownCodeBlockProcessor("pdf", async (src, el, ctx) => {
// Get Parameters
let parameters: PdfNodeParameters = null;
try {
Expand All @@ -37,8 +36,15 @@ export default class BetterPDFPlugin extends Plugin {

//Create PDF Node
if (parameters !== null) {
// console.log("Creating PDF Node with parameters: ", parameters);
try {

console.log(parameters.url);
if (parameters.url.startsWith("./")) {
// find the substring of path all the way to the last slash
const filePath = ctx.sourcePath;
const folderPath = filePath.substring(0, filePath.lastIndexOf("/"));
parameters.url = folderPath + "/" + parameters.url.substring(2, parameters.url.length);
}
//Read Document
const arrayBuffer = await this.app.vault.adapter.readBinary(parameters.url);
const buffer = Buffer.from(arrayBuffer);
Expand Down
Loading

0 comments on commit 933810c

Please sign in to comment.