Skip to content

Commit

Permalink
test: Add missing tests for extendMarkdownIt
Browse files Browse the repository at this point in the history
  • Loading branch information
svsool committed Aug 1, 2020
1 parent 49f6ba4 commit 9d2074d
Showing 1 changed file with 127 additions and 0 deletions.
127 changes: 127 additions & 0 deletions src/features/extendMarkdownIt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,131 @@ describe('extendMarkdownIt feature', () => {
"
`);
});

it('should not render a link within code span', async () => {
const name = rndName();

await createFile(`${name}.md`, '# Hello world');

const md = extendMarkdownIt(MarkdownIt());

const html = md.render(`\`[[${name}]]\``);

expect(html.replace(name, 'note')).toMatchInlineSnapshot(`
"<p><code>[[note]]</code></p>
"
`);
});

it('should not render a link within fenced code block', async () => {
const name = rndName();

await createFile(`${name}.md`, '# Hello world');

const md = extendMarkdownIt(MarkdownIt());

const html = md.render(`
\`\`\`
Preceding text
[[${name}]]
Following text
\`\`\`
`);

expect(html.replace(name, 'note')).toMatchInlineSnapshot(`
"<pre><code>\`\`\`
Preceding text
[[note]]
Following text
\`\`\`
</code></pre>
"
`);
});

it('should not render embedded note within code span', async () => {
const name = rndName();

await createFile(`${name}.md`, '# Hello world');

const md = extendMarkdownIt(MarkdownIt());

const html = md.render(`\`![[${name}]]\``);

expect(html.replace(name, 'note')).toMatchInlineSnapshot(`
"<p><code>![[note]]</code></p>
"
`);
});

it('should not render an image within code span', async () => {
const name = rndName();

await createFile(`${name}.png`);

const md = extendMarkdownIt(MarkdownIt());

const html = md.render(`\`![[${name}]]\``);

expect(html.replace(name, 'image')).toMatchInlineSnapshot(`
"<p><code>![[image]]</code></p>
"
`);
});

it('should not render embedded note within fenced code block', async () => {
const name = rndName();

await createFile(`${name}.md`, '# Hello world');

const md = extendMarkdownIt(MarkdownIt());

const html = md.render(`
\`\`\`
Preceding text
![[${name}]]
Following text
\`\`\`
`);

expect(html.replace(name, 'note')).toMatchInlineSnapshot(`
"<pre><code>\`\`\`
Preceding text
![[note]]
Following text
\`\`\`
</code></pre>
"
`);
});

it('should not render an image within fenced code block', async () => {
const name = rndName();

await createFile(`${name}.png`);

const md = extendMarkdownIt(MarkdownIt());

const html = md.render(`
"<pre><code>\`\`\`
Preceding text
![[image.png]]
Following text
\`\`\`
</code></pre>
"
`);

expect(html.replace(name, 'image')).toMatchInlineSnapshot(`
"<pre><code> &quot;&lt;pre&gt;&lt;code&gt;\`\`\`
Preceding text
![[image.png]]
Following text
\`\`\`
&lt;/code&gt;&lt;/pre&gt;
&quot;
</code></pre>
"
`);
});
});

0 comments on commit 9d2074d

Please sign in to comment.