Skip to content

Commit 7d673b6

Browse files
committed
fix #13
1 parent ed3359b commit 7d673b6

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

jsEngine/JsMDRC.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ export class JsMDRC extends MarkdownRenderChild {
3636

3737
buildExecutionContext(): JsExecutionContext {
3838
// console.log(this.ctx);
39-
const file = this.getExecutionFile()!;
39+
const file = this.getExecutionFile();
4040
return {
4141
file: file,
42-
metadata: this.plugin.app.metadataCache.getFileCache(file),
42+
metadata: file === undefined ? undefined : this.plugin.app.metadataCache.getFileCache(file) ?? undefined,
4343
block: undefined,
4444
};
4545
}

jsEngine/api/Internal.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ export class InternalAPI {
6868
}
6969
}
7070

71+
/**
72+
* Gets the execution context for a specific file, throws when the file does not exist.
73+
*
74+
* @param path
75+
*/
7176
public async getContextForFile(path: string): Promise<JsExecutionContext> {
7277
const file = this.apiInstance.app.vault.getAbstractFileByPath(path);
7378
if (!file || !(file instanceof TFile)) {
@@ -78,7 +83,7 @@ export class InternalAPI {
7883

7984
return {
8085
file: file,
81-
metadata: metadata,
86+
metadata: metadata ?? undefined,
8287
block: undefined,
8388
};
8489
}

jsEngine/engine/JsExecution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export interface JsExecutionContext {
1818
/**
1919
* The file that the execution was triggered from.
2020
*/
21-
file: TFile;
21+
file: TFile | undefined;
2222
/**
2323
* The metadata of the file that the execution was triggered from.
2424
*/
25-
metadata: CachedMetadata | null;
25+
metadata: CachedMetadata | undefined;
2626
/**
2727
* Currently unused.
2828
*/

0 commit comments

Comments
 (0)