Skip to content

Commit

Permalink
fix(hack-pdf): fix internal links failed to export
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenlx committed Jan 16, 2022
1 parent 70194ba commit 000472f
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/hack-pdf.ts
Expand Up @@ -3,25 +3,23 @@ import { MarkdownView, TFile, Vault } from "obsidian";

import TableExtended from "./tx-main";

const placeholder = "export2pdf";

const Export2PDFHack = (plugin: TableExtended) => {
const unloaders = [
around(MarkdownView.prototype, {
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
printToPdf: (original) =>
function (this: MarkdownView) {
plugin.print2pdfFileCache = this.file;
// @ts-ignore
this.file = placeholder;
// shalow copy the file to provide basic info
this.file = { ...this.file, export2pdf: true } as any;
original.call(this);
this.file = plugin.print2pdfFileCache;
},
}),
around(Vault.prototype, {
cachedRead: (original) =>
async function (this: Vault, input: TFile | string) {
if (input === placeholder) {
if (!(input instanceof TFile) && (input as any)?.export2pdf) {
const file = plugin.print2pdfFileCache;
if (!file) {
throw new Error(
Expand Down

0 comments on commit 000472f

Please sign in to comment.