Skip to content

Commit

Permalink
Adjusts in the regex used to replace spaces with dashes in the header…
Browse files Browse the repository at this point in the history
… of wiki links and adjusted the unit tests
  • Loading branch information
leonardo.farias committed Nov 2, 2023
1 parent 85bb6cb commit 1663b09
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/remark-wiki-link/src/lib/fromMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function fromMarkdown(opts: FromMarkdownOptions = {}) {

// remove leading # if the target is a heading on the same page
const displayName = alias || target.replace(/^#/, "");
const headingId = heading.replace(/\s+/, "-").toLowerCase();
const headingId = heading.replace(/\s+/g, "-").toLowerCase();
let classNames = wikiLinkClassName;
if (!matchingPermalink) {
classNames += " " + newClassName;
Expand Down
2 changes: 1 addition & 1 deletion packages/remark-wiki-link/src/lib/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function html(opts: HtmlOptions = {}) {
// remove leading # if the target is a heading on the same page
const displayName = alias || target.replace(/^#/, "");
// replace spaces with dashes and lowercase headings
const headingId = heading.replace(/\s+/, "-").toLowerCase();
const headingId = heading.replace(/\s+/g, "-").toLowerCase();
let classNames = wikiLinkClassName;
if (!matchingPermalink) {
classNames += " " + newClassName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,11 @@ describe("micromark-extension-wiki-link", () => {

describe("Links with special characters", () => {
test("parses a link with special characters and symbols", () => {
const serialized = micromark("[[li nk-w(i)th-àcèô íã_a(n)d_underline!:ª%@'*º$ °~./\\#li nk-w(i)th-àcèô íã_a(n)d_underline!:ª%@'*º$ °~./\\]]", "ascii", {
const serialized = micromark("[[li nk-w(i)th-àcèô íã_a(n)d_underline!:ª%@'*º$ °~./\\#LI NK-W(i)th-àcèô íã_a(n)d_uNdErlinE!:ª%@'*º$ °~./\\]]", "ascii", {
extensions: [syntax()],
htmlExtensions: [html() as any],
});
const prefixExpected = '<p><a href="li nk-w(i)th-àcèô íã_a(n)d_underline!:ª%@\'*º$ °~./\\#'; // after the '#' symbol it's replacing spaces with dashes randomly not permiting create expected output after the symbol
expect(serialized).toBe(prefixExpected + serialized.substring(prefixExpected.length, serialized.length));
expect(serialized).toBe(`<p><a href="li nk-w(i)th-àcèô íã_a(n)d_underline!:ª%@'*º$ °~./\\#li-nk-w(i)th-àcèô-íã_a(n)d_underline!:ª%@'*º$-°~./\\" class="internal new">li nk-w(i)th-àcèô íã_a(n)d_underline!:ª%@'*º$ °~./\\#LI NK-W(i)th-àcèô íã_a(n)d_uNdErlinE!:ª%@'*º$ °~./\\</a></p>`);
});
})
});
6 changes: 3 additions & 3 deletions packages/remark-wiki-link/test/remarkWikiLink.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ describe("remark-wiki-link", () => {
test("parses a link with special characters and symbols", () => {
const processor = unified().use(markdown).use(wikiLinkPlugin);

let ast = processor.parse("[[li nk-w(i)th-àcèô íã_a(n)d_underline!:ª%@'*º$ °~./\\#li-nk-w(i)th-àcèô íã_a(n)d_underline!:ª%@'*º$ °~./\\]]");
let ast = processor.parse("[[li nk-w(i)th-àcèô íã_a(n)d_underline!:ª%@'*º$ °~./\\#li-nk-w(i)th-àcèô íã_a(n)D_UNDERLINE!:ª%@'*º$ °~./\\]]");
ast = processor.runSync(ast);
expect(select("wikiLink", ast)).not.toEqual(null);

Expand All @@ -378,10 +378,10 @@ describe("remark-wiki-link", () => {
"internal new"
);
expect((node.data?.hProperties as any).href).toEqual(
"li nk-w(i)th-àcèô íã_a(n)d_underline!:ª%@'*º$ °~./\\#li-nk-w(i)th-àcèô-íã_a(n)d_underline!:ª%@'*º$ °~./\\"
"li nk-w(i)th-àcèô íã_a(n)d_underline!:ª%@'*º$ °~./\\#li-nk-w(i)th-àcèô-íã_a(n)d_underline!:ª%@'*º$-°~./\\"
);
expect((node.data?.hChildren as any)[0].value).toEqual(
"li nk-w(i)th-àcèô íã_a(n)d_underline!:ª%@'*º$ °~./\\#li-nk-w(i)th-àcèô íã_a(n)d_underline!:ª%@'*º$ °~./\\"
"li nk-w(i)th-àcèô íã_a(n)d_underline!:ª%@'*º$ °~./\\#li-nk-w(i)th-àcèô íã_a(n)D_UNDERLINE!:ª%@'*º$ °~./\\"
);
})
});
Expand Down

0 comments on commit 1663b09

Please sign in to comment.