Skip to content

Commit 6200ab0

Browse files
authored
Merge pull request #266 from mayurankv/fix/img-links-broken
Fix app://local deprecation
2 parents 80666cb + 8e5bea4 commit 6200ab0

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

package-lock.json

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/transforms/Magic.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313

1414
import * as os from "os";
15+
import {Platform} from 'obsidian';
1516
import { TOGGLE_HTML_SIGIL } from "src/Outputter";
1617

1718
// Regex for all languages.
@@ -41,8 +42,8 @@ const MAXIMA_PLOT_REGEX = /^plot2d\s*\(.*\[.+\]\)\s*[$;]/gm;
4142
*/
4243
export function insertVaultPath(source: string, vaultPath: string): string {
4344
source = source.replace(VAULT_PATH_REGEX, `"${vaultPath.replace(/\\/g, "/")}"`);
44-
source = source.replace(VAULT_URL_REGEX, `"app://local/${vaultPath.replace(/\\/g, "/")}"`);
45-
source = source.replace(VAULT_REGEX, `"app://local/${vaultPath.replace(/\\/g, "/")}"`);
45+
source = source.replace(VAULT_URL_REGEX, `"${Platform.resourcePathPrefix + vaultPath.replace(/\\/g, "/")}"`);
46+
source = source.replace(VAULT_REGEX, `"${Platform.resourcePathPrefix + vaultPath.replace(/\\/g, "/")}"`);
4647

4748
return source;
4849
}
@@ -57,8 +58,8 @@ export function insertVaultPath(source: string, vaultPath: string): string {
5758
*/
5859
export function insertNotePath(source: string, notePath: string): string {
5960
source = source.replace(CURRENT_NOTE_PATH_REGEX, `"${notePath.replace(/\\/g, "/")}"`);
60-
source = source.replace(CURRENT_NOTE_URL_REGEX, `"app://local/${notePath.replace(/\\/g, "/")}"`);
61-
source = source.replace(CURRENT_NOTE_REGEX, `"app://local/${notePath.replace(/\\/g, "/")}"`);
61+
source = source.replace(CURRENT_NOTE_URL_REGEX, `"${Platform.resourcePathPrefix + notePath.replace(/\\/g, "/")}"`);
62+
source = source.replace(CURRENT_NOTE_REGEX, `"${Platform.resourcePathPrefix + notePath.replace(/\\/g, "/")}"`);
6263

6364
return source;
6465
}
@@ -141,7 +142,7 @@ export function addInlinePlotsToR(source: string): string {
141142
const matches = source.matchAll(R_PLOT_REGEX);
142143
for (const match of matches) {
143144
const tempFile = `${os.tmpdir()}/temp_${Date.now()}.png`.replace(/\\/g, "/");
144-
const substitute = `png("${tempFile}"); ${match[0]}; dev.off(); cat('${TOGGLE_HTML_SIGIL}<img src="app://local/${tempFile}" align="center">${TOGGLE_HTML_SIGIL}')`;
145+
const substitute = `png("${tempFile}"); ${match[0]}; dev.off(); cat('${TOGGLE_HTML_SIGIL}<img src="${Platform.resourcePathPrefix + tempFile}" align="center">${TOGGLE_HTML_SIGIL}')`;
145146

146147
source = source.replace(match[0], substitute);
147148
}
@@ -246,7 +247,7 @@ export function addInlinePlotsToOctave(source: string): string {
246247
const matches = source.matchAll(OCTAVE_PLOT_REGEX);
247248
for (const match of matches) {
248249
const tempFile = `${os.tmpdir()}/temp_${Date.now()}.png`.replace(/\\/g, "/");
249-
const substitute = `${match[0]}; print -dpng ${tempFile}; disp('${TOGGLE_HTML_SIGIL}<img src="app://local/${tempFile}" align="center">${TOGGLE_HTML_SIGIL}');`;
250+
const substitute = `${match[0]}; print -dpng ${tempFile}; disp('${TOGGLE_HTML_SIGIL}<img src="${Platform.resourcePathPrefix + tempFile}" align="center">${TOGGLE_HTML_SIGIL}');`;
250251

251252
source = source.replace(match[0], substitute);
252253
}
@@ -259,7 +260,7 @@ export function addInlinePlotsToMaxima(source: string): string {
259260
for (const match of matches) {
260261
const tempFile = `${os.tmpdir()}/temp_${Date.now()}.png`.replace(/\\/g, "/");
261262
const updated_plot_call = match[0].substring(0, match[0].lastIndexOf(')')) + `, [png_file, "${tempFile}"])`;
262-
const substitute = `${updated_plot_call}; print ('${TOGGLE_HTML_SIGIL}<img src="app://local/${tempFile}" align="center">${TOGGLE_HTML_SIGIL}');`;
263+
const substitute = `${updated_plot_call}; print ('${TOGGLE_HTML_SIGIL}<img src="${Platform.resourcePathPrefix + tempFile}" align="center">${TOGGLE_HTML_SIGIL}');`;
263264

264265
source = source.replace(match[0], substitute);
265266
}

0 commit comments

Comments
 (0)