Skip to content

Commit

Permalink
feat(#53): add test for markdown parser ignoring wikilink within code…
Browse files Browse the repository at this point in the history
… blocks
  • Loading branch information
carbontwelve committed Nov 7, 2024
1 parent d7e319a commit f3dc0a5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/fixtures/within-code.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>Test Markdown File</h1>
<pre><code>[[wiki link]]</code></pre>
<p>This contains a wiki link <code>[[wiki link]]</code> within an inline code element. This sentance does not: <a href="/wiki-link/">Wiki Link</a>.</p>
7 changes: 7 additions & 0 deletions tests/fixtures/within-code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Test Markdown File

```
[[wiki link]]
```

This contains a wiki link `[[wiki link]]` within an inline code element. This sentance does not: [[wiki link]].
27 changes: 27 additions & 0 deletions tests/markdown-wikilink-renderer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,33 @@ test('inline rule correctly parses single embed', t => {
);
});

test('inline rule ignores wikilink within code and pre tags', t => {
const wikilinkParser = new WikilinkParser(opts, new Set(), new Map());

wikilinkParser.linkCache.set('[[wiki link]]', {
title: 'Wiki Link',
link: '[[wiki link]]',
href: '/wiki-link/',
content: '<a href="/wiki-link/">Wiki Link</a>',
isEmbed: false,
});

const md = MarkdownIt({html: true});
md.inline.ruler.push('inline_wikilink', wikilinkInlineRule(
wikilinkParser
));

md.renderer.rules.inline_wikilink = wikilinkRenderRule();

const markdown = fs.readFileSync(__dirname + '/fixtures/within-code.md', {encoding:'utf8', flag:'r'});
const html = fs.readFileSync(__dirname + '/fixtures/within-code.html', {encoding:'utf8', flag:'r'});

t.is(
normalize(md.render(markdown)),
normalize(html)
);
});

test('inline rule correctly parses mixed wikilink and embed in multiline input', t => {
const wikilinkParser = new WikilinkParser(opts, new Set(), new Map());

Expand Down

0 comments on commit f3dc0a5

Please sign in to comment.