mirror of
https://github.com/quartz-community/utils.git
synced 2026-07-22 02:50:27 +00:00
fix: match obsidian-importer illegal character filter in slugs
This commit is contained in:
parent
e09d8b0bbc
commit
37b89c3fbe
2 changed files with 19 additions and 0 deletions
|
|
@ -303,6 +303,7 @@ export function slugifyPath(s: string): string {
|
|||
.replace(/%/g, "-percent")
|
||||
.replace(/\?/g, "")
|
||||
.replace(/#/g, "")
|
||||
.replace(/[<>:"|*]/g, "")
|
||||
.toLowerCase(),
|
||||
)
|
||||
.join("/")
|
||||
|
|
|
|||
|
|
@ -287,6 +287,24 @@ describe("slugifyPath", () => {
|
|||
it("lowercases for case-insensitive matching (Obsidian parity)", () => {
|
||||
expect(slugifyPath("Compendium/Species/Dryad/Apple")).toBe("compendium/species/dryad/apple");
|
||||
});
|
||||
|
||||
it('removes filesystem-illegal characters (< > : " | *)', () => {
|
||||
expect(slugifyPath("Alias with <illegal> chars")).toBe("alias-with-illegal-chars");
|
||||
});
|
||||
|
||||
it("removes colons and pipes", () => {
|
||||
expect(slugifyPath("Title: Subtitle | Part")).toBe("title-subtitle--part");
|
||||
});
|
||||
|
||||
it("removes asterisks and quotes", () => {
|
||||
expect(slugifyPath('What is "AI"*')).toBe("what-is-ai");
|
||||
});
|
||||
|
||||
it("handles mixed illegal characters across path segments", () => {
|
||||
expect(slugifyPath("Guides/X-Men: First Class/Notes <draft>")).toBe(
|
||||
"guides/x-men-first-class/notes-draft",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("splitAnchor", () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue