-
-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathreplacements.ts
More file actions
13 lines (10 loc) · 647 Bytes
/
replacements.ts
File metadata and controls
13 lines (10 loc) · 647 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
import type { MarkdownPostProcessorContext } from "obsidian";
import type { TaskQuery } from "@/query/schema/tasks";
export function applyReplacements(query: TaskQuery, ctx: MarkdownPostProcessorContext) {
// Replace {filename} with the base file name of file where the query originated.
const baseFileName = ctx.sourcePath.replace(/.*\//, "").replace(/\.md$/i, "");
query.filter = query.filter.replace(/{{filename}}/g, baseFileName);
// Normalize Unicode whitespace characters (e.g., non-breaking spaces, em spaces)
// to regular ASCII spaces to prevent API errors.
query.filter = query.filter.replace(/[\p{Zs}]/gu, " ").trim();
}