12
12
*/
13
13
14
14
import * as os from "os" ;
15
+ import { Platform } from 'obsidian' ;
15
16
import { TOGGLE_HTML_SIGIL } from "src/Outputter" ;
16
17
17
18
// Regex for all languages.
@@ -41,8 +42,8 @@ const MAXIMA_PLOT_REGEX = /^plot2d\s*\(.*\[.+\]\)\s*[$;]/gm;
41
42
*/
42
43
export function insertVaultPath ( source : string , vaultPath : string ) : string {
43
44
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, "/" ) } "` ) ;
46
47
47
48
return source ;
48
49
}
@@ -57,8 +58,8 @@ export function insertVaultPath(source: string, vaultPath: string): string {
57
58
*/
58
59
export function insertNotePath ( source : string , notePath : string ) : string {
59
60
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, "/" ) } "` ) ;
62
63
63
64
return source ;
64
65
}
@@ -141,7 +142,7 @@ export function addInlinePlotsToR(source: string): string {
141
142
const matches = source . matchAll ( R_PLOT_REGEX ) ;
142
143
for ( const match of matches ) {
143
144
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 } ')` ;
145
146
146
147
source = source . replace ( match [ 0 ] , substitute ) ;
147
148
}
@@ -246,7 +247,7 @@ export function addInlinePlotsToOctave(source: string): string {
246
247
const matches = source . matchAll ( OCTAVE_PLOT_REGEX ) ;
247
248
for ( const match of matches ) {
248
249
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 } ');` ;
250
251
251
252
source = source . replace ( match [ 0 ] , substitute ) ;
252
253
}
@@ -259,7 +260,7 @@ export function addInlinePlotsToMaxima(source: string): string {
259
260
for ( const match of matches ) {
260
261
const tempFile = `${ os . tmpdir ( ) } /temp_${ Date . now ( ) } .png` . replace ( / \\ / g, "/" ) ;
261
262
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 } ');` ;
263
264
264
265
source = source . replace ( match [ 0 ] , substitute ) ;
265
266
}
0 commit comments