31 lines
1.3 KiB
TypeScript
31 lines
1.3 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { documentLinks } from "../../../src/lib/editor/documentLinks.ts";
|
|
import { tableLinkLabelPosition } from "../../../src/lib/editor/tableLinkSource.ts";
|
|
|
|
test("table link reveal retains the clicked character through Markdown label marks", () => {
|
|
for (const [source, offset, prefix] of [
|
|
["[Roadmap](docs/roadmap.md)", 5, "[Roadm"],
|
|
['**Prefix** [One](same.md) + [Sec**ond**](same.md "Title")', 4, '**Prefix** [One](same.md) + [Sec**o'],
|
|
["[A \\*star](note.md)", 3, "[A \\*"],
|
|
["[Use `code`](note.md)", 5, "[Use `c"],
|
|
["<https://example.org>", 8, "<https://"],
|
|
] as const) {
|
|
const link = documentLinks(source).at(-1)!;
|
|
assert.equal(source.slice(0, tableLinkLabelPosition(source, link, offset)), prefix);
|
|
}
|
|
});
|
|
|
|
test("table wiki links retain literal label text, aliases, spaces, and escaped pipes", () => {
|
|
for (const [source, offset, prefix] of [
|
|
["[[guide\\|Guide]]", 3, "[[guide\\|Gui"],
|
|
["[[guide\\|**Alias**]]", 2, "[[guide\\|**"],
|
|
["[[ Guide ]]", 3, "[[ G"],
|
|
["[[Guide\\|]]", 2, "[[Gu"],
|
|
["[[guide\\|A\\|B]]", 2, "[[guide\\|A\\|"],
|
|
] as const) {
|
|
const link = documentLinks(source)[0];
|
|
assert.equal(source.slice(0, tableLinkLabelPosition(source, link, offset)), prefix);
|
|
}
|
|
});
|