mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 19:36:12 +01:00
chore(share): improve slugification to strip diacritics cleanly
This commit is contained in:
@@ -681,3 +681,33 @@ describe("#normalizeCustomHandlerPattern", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("#slugify", () => {
|
||||||
|
it("should return a slugified string", () => {
|
||||||
|
const testString = "This is a Test String! With unicode & Special #Chars.";
|
||||||
|
const expectedSlug = "this-is-a-test-string-with-unicode-special-chars";
|
||||||
|
const result = utils.slugify(testString);
|
||||||
|
expect(result).toBe(expectedSlug);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("supports CJK characters without alteration", () => {
|
||||||
|
const testString = "测试中文字符";
|
||||||
|
const expectedSlug = "测试中文字符";
|
||||||
|
const result = utils.slugify(testString);
|
||||||
|
expect(result).toBe(expectedSlug);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("supports Cyrillic characters without alteration", () => {
|
||||||
|
const testString = "Тестирование кириллических символов";
|
||||||
|
const expectedSlug = "тестирование-кириллических-символов";
|
||||||
|
const result = utils.slugify(testString);
|
||||||
|
expect(result).toBe(expectedSlug);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("removes diacritic marks from characters", () => {
|
||||||
|
const testString = "Café naïve façade jalapeño";
|
||||||
|
const expectedSlug = "cafe-naive-facade-jalapeno";
|
||||||
|
const result = utils.slugify(testString);
|
||||||
|
expect(result).toBe(expectedSlug);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -499,7 +499,8 @@ export function formatSize(size: number | null | undefined) {
|
|||||||
|
|
||||||
function slugify(text: string) {
|
function slugify(text: string) {
|
||||||
return text
|
return text
|
||||||
.normalize("NFKD") // handles accents like é → e
|
.normalize("NFKD") // decompose accents
|
||||||
|
.replace(/\p{Mark}/gu, "") // remove diacritics cleanly
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.replace(/[^\p{Letter}\p{Number}]+/gu, "-") // keep Unicode letters/numbers
|
.replace(/[^\p{Letter}\p{Number}]+/gu, "-") // keep Unicode letters/numbers
|
||||||
.replace(/(^-|-$)+/g, ""); // trim leading/trailing dashes
|
.replace(/(^-|-$)+/g, ""); // trim leading/trailing dashes
|
||||||
|
|||||||
Reference in New Issue
Block a user