Skip to content

Commit

Permalink
Merge pull request #74 from markscamilleri/bugfix-markdown-link
Browse files Browse the repository at this point in the history
fix(markdown-links): Allowing for escaped square brackets in markdown links
  • Loading branch information
sawhney17 authored Feb 8, 2024
2 parents c246b2e + d3ad6b8 commit 4abbe6d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function replaceContentWithPageLinks(

// Broken Markdown links with nested pages won't be detected by this regex and have to be fixed manually.
// Example: [[[page]] This is a broken Markdown link](http://example.com)
content = content.replaceAll(/\[[^\[\]]+\]\([^\(\)]+\)/g, (match) => {
content = content.replaceAll(/\[(([^\[\]]|\\\[|\\\])+)\]\(.*\)/g, (match) => {
markdownLinkTracker.push(match);
console.debug({ LogseqAutomaticLinker: "Markdown link found", match });
return MARKDOWN_LINK_PLACEHOLDER;
Expand Down
8 changes: 5 additions & 3 deletions tests/functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ describe("replaceContentWithPageLinks()", () => {

it("should preserve Markdown links", () => {
let [content, update] = replaceContentWithPageLinks(
["page", "link"],
["page", "link", "Logseq"],
`This page has a link: [page link will not be touched](http://a.com)
[another page](http://b.com) also with a link`,
[another page](http://b.com) also with a link
[\\[This\\] is a Logseq page](https://logseq.com)`,
false,
false
);
expect(content).toBe(
`This [[page]] has a [[link]]: [page link will not be touched](http://a.com)
[another page](http://b.com) also with a [[link]]`
[another page](http://b.com) also with a [[link]]
[\\[This\\] is a Logseq page](https://logseq.com)`
);
expect(update).toBe(true);
});
Expand Down

0 comments on commit 4abbe6d

Please sign in to comment.