extra checks on markdown links

This commit is contained in:
Maxime Cannoodt 2022-07-06 14:19:45 +02:00
parent e603cbc94b
commit 50aac161c4
4 changed files with 12 additions and 2 deletions

View File

@ -20,7 +20,7 @@
<dfn class="not-italic" title="Internal link"> <dfn class="not-italic" title="Internal link">
<span class="underline cursor-not-allowed inline-flex items-center"> <span class="underline cursor-not-allowed inline-flex items-center">
<span class="text-[#705dcf] opacity-50"> <span class="internal-link text-[#705dcf] opacity-50">
{#if useSlot} {#if useSlot}
<slot /> <slot />
{:else} {:else}

View File

@ -15,7 +15,7 @@
{#if isWebLink} {#if isWebLink}
<span class="underline cursor-not-allowed inline-flex items-center font-normal"> <span class="underline cursor-not-allowed inline-flex items-center font-normal">
<a {href} {title} class="text-[#705dcf]"><slot /></a> <a {href} {title} class="external-link text-[#705dcf]"><slot /></a>
<span class="h-3 mb-2 text-zinc-400 ml-0.5"><LinkIcon /></span> <span class="h-3 mb-2 text-zinc-400 ml-0.5"><LinkIcon /></span>
</span> </span>
{:else} {:else}

View File

@ -10,35 +10,41 @@ describe('rendering [[internal]] links', async () => {
render(MarkdownRenderer, { plaintext: plaintext }); render(MarkdownRenderer, { plaintext: plaintext });
const linkEl = await screen.findByText(/^Normal internal link$/); const linkEl = await screen.findByText(/^Normal internal link$/);
expect(linkEl).toBeInTheDocument(); expect(linkEl).toBeInTheDocument();
expect(linkEl).toHaveClass('internal-link');
}); });
it('Renders [[links|with alias]] correctly', async () => { it('Renders [[links|with alias]] correctly', async () => {
render(MarkdownRenderer, { plaintext: plaintext }); render(MarkdownRenderer, { plaintext: plaintext });
const linkEl = await screen.findByText(/^Link with alias$/); const linkEl = await screen.findByText(/^Link with alias$/);
expect(linkEl).toBeInTheDocument(); expect(linkEl).toBeInTheDocument();
expect(linkEl).toHaveClass('internal-link');
}); });
it('Renders [[links#heading]] correctly', async () => { it('Renders [[links#heading]] correctly', async () => {
render(MarkdownRenderer, { plaintext: plaintext }); render(MarkdownRenderer, { plaintext: plaintext });
const linkEl = await screen.findByText(/^Page with headings > heading A$/); const linkEl = await screen.findByText(/^Page with headings > heading A$/);
expect(linkEl).toBeInTheDocument(); expect(linkEl).toBeInTheDocument();
expect(linkEl).toHaveClass('internal-link');
}); });
it('Renders [[links#heading|with alias]] correctly', async () => { it('Renders [[links#heading|with alias]] correctly', async () => {
render(MarkdownRenderer, { plaintext: plaintext }); render(MarkdownRenderer, { plaintext: plaintext });
const linkEl = await screen.findByText(/^Link with heading alias$/); const linkEl = await screen.findByText(/^Link with heading alias$/);
expect(linkEl).toBeInTheDocument(); expect(linkEl).toBeInTheDocument();
expect(linkEl).toHaveClass('internal-link');
}); });
it('Renders [[links#heading|with alias#fakeheading]] correctly', async () => { it('Renders [[links#heading|with alias#fakeheading]] correctly', async () => {
render(MarkdownRenderer, { plaintext: plaintext }); render(MarkdownRenderer, { plaintext: plaintext });
const linkEl = await screen.findByText(/^Link with heading alias#false heading$/); const linkEl = await screen.findByText(/^Link with heading alias#false heading$/);
expect(linkEl).toBeInTheDocument(); expect(linkEl).toBeInTheDocument();
expect(linkEl).toHaveClass('internal-link');
}); });
it('Does not render [[]] empty links', async () => { it('Does not render [[]] empty links', async () => {
render(MarkdownRenderer, { plaintext: plaintext }); render(MarkdownRenderer, { plaintext: plaintext });
const textEl = await screen.findByText('[[]]', { exact: false }); const textEl = await screen.findByText('[[]]', { exact: false });
expect(textEl).toBeInTheDocument(); expect(textEl).toBeInTheDocument();
expect(textEl).not.toHaveClass('internal-link');
}); });
}); });

View File

@ -9,23 +9,27 @@ describe('rendering [md style](links)', async () => {
render(MarkdownRenderer, { plaintext: plaintext }); render(MarkdownRenderer, { plaintext: plaintext });
const linkEl = await screen.findByText(/^Classic internal link \(URL encoded\)$/); const linkEl = await screen.findByText(/^Classic internal link \(URL encoded\)$/);
expect(linkEl).toBeInTheDocument(); expect(linkEl).toBeInTheDocument();
expect(linkEl).toHaveClass('internal-link');
}); });
it('Renders URL-encoded internal links correctly', async () => { it('Renders URL-encoded internal links correctly', async () => {
render(MarkdownRenderer, { plaintext: plaintext }); render(MarkdownRenderer, { plaintext: plaintext });
const linkEl = await screen.findByText(/^Classic internal link \(tag format\)$/); const linkEl = await screen.findByText(/^Classic internal link \(tag format\)$/);
expect(linkEl).toBeInTheDocument(); expect(linkEl).toBeInTheDocument();
expect(linkEl).toHaveClass('internal-link');
}); });
it('Renders http links correctly', async () => { it('Renders http links correctly', async () => {
render(MarkdownRenderer, { plaintext: plaintext }); render(MarkdownRenderer, { plaintext: plaintext });
const linkEl = await screen.findByText(/^Wikipedia \(http\)$/); const linkEl = await screen.findByText(/^Wikipedia \(http\)$/);
expect(linkEl).toBeInTheDocument(); expect(linkEl).toBeInTheDocument();
expect(linkEl).toHaveClass('external-link');
}); });
it('Renders https links correctly', async () => { it('Renders https links correctly', async () => {
render(MarkdownRenderer, { plaintext: plaintext }); render(MarkdownRenderer, { plaintext: plaintext });
const linkEl = await screen.findByText(/Wikipedia \(https\)$/); const linkEl = await screen.findByText(/Wikipedia \(https\)$/);
expect(linkEl).toBeInTheDocument(); expect(linkEl).toBeInTheDocument();
expect(linkEl).toHaveClass('external-link');
}); });
}); });