diff --git a/webapp/CHANGELOG.md b/webapp/CHANGELOG.md index f02cd68..9e62e66 100644 --- a/webapp/CHANGELOG.md +++ b/webapp/CHANGELOG.md @@ -2,6 +2,7 @@ ## [2022-08-07] +- fix: 🐛 collapsed/uncollapsed callout syntax now correctly renders as a callout block instead of a block quote. - fix: 🐛 text highlights (`==highlight==` syntax) are now more legibile in dark mode. - fix: 🐛 code blocks no longer render as "undefined" for unregistered languages (e.g. Dataview or Toggl query blocks). diff --git a/webapp/src/lib/components/Callout.svelte b/webapp/src/lib/components/Callout.svelte index c73bb45..62d5c53 100644 --- a/webapp/src/lib/components/Callout.svelte +++ b/webapp/src/lib/components/Callout.svelte @@ -12,10 +12,10 @@ $: if (content) { const titleElement = content.getElementsByTagName('p')[0]; - const match = titleElement.innerText.split('\n')[0].match(/\[!(.+)\](?:\s(.+))?/); + const match = titleElement.innerText.split('\n')[0].match(/\[!(.+)\]([+-]?)(?:\s(.+))?/); if (match) { type = match[1]?.trim(); - title = match[2]?.trim() ?? type[0].toUpperCase() + type.substring(1).toLowerCase(); + title = match[3]?.trim() ?? type[0].toUpperCase() + type.substring(1).toLowerCase(); } color = `--${getCalloutColor(type)}`; diff --git a/webapp/src/lib/marked/renderers/Blockquote.svelte b/webapp/src/lib/marked/renderers/Blockquote.svelte index 07c6ab8..2d59b20 100644 --- a/webapp/src/lib/marked/renderers/Blockquote.svelte +++ b/webapp/src/lib/marked/renderers/Blockquote.svelte @@ -3,7 +3,7 @@ export let raw: string; - let isCallout: boolean = raw.split('\n')[0].match(/>\s?\[!(.+)\](\s.*|$)/) != null; + let isCallout: boolean = raw.split('\n')[0].match(/>\s?\[!(.+)\]([+-]?)(\s.*|$)/) != null; {#if isCallout} diff --git a/webapp/src/test/markdown/callout.test.ts b/webapp/src/test/markdown/callout.test.ts index a3f9ba8..7e14037 100644 --- a/webapp/src/test/markdown/callout.test.ts +++ b/webapp/src/test/markdown/callout.test.ts @@ -2,19 +2,52 @@ import { render, screen } from '@testing-library/svelte'; import { readMd } from './util'; import MarkdownRenderer from '$lib/components/MarkdownRenderer.svelte'; -describe('Rendering callouts', async () => { - const plaintext = await readMd('callout.md'); +const testCases = [ + { + title: 'Don!t forget to account for non-letters! //fsd \\n', + content: 'Sample text.', + markdown: ` +> [!Warning] Don!t forget to account for non-letters! //fsd \\n +> Sample text. + ` + }, + { + title: 'Regular callout', + content: 'Sample text.', + markdown: ` +> [!NOTE] Regular callout +> Sample text. + ` + }, + { + title: 'Collapsed callout', + content: 'Sample text.', + markdown: ` +> [!NOTE]- Collapsed callout +> Sample text. + ` + }, + { + title: 'Uncollapsed callout', + content: 'Sample text.', + markdown: ` +> [!NOTE]+ Uncollapsed callout +> Sample text. +` + } +]; +describe.each(testCases)('Rendering callouts', async (testCase) => { it('Renders callout title correctly ', async () => { - render(MarkdownRenderer, { plaintext: plaintext }); - const titleEl = await screen.findByText('Don!t forget to account for non-letters! //fsd \\n'); + render(MarkdownRenderer, { plaintext: testCase.markdown }); + const titleEl = await screen.findByText(testCase.title); expect(titleEl).toBeInTheDocument(); expect(titleEl).toHaveClass('callout-title'); }); it('Renders callout content correctly ', async () => { - render(MarkdownRenderer, { plaintext: plaintext }); - const contentEl = await screen.findByText('Sample text.'); + render(MarkdownRenderer, { plaintext: testCase.markdown }); + const contentEl = await screen.findByText(testCase.content); expect(contentEl).toBeInTheDocument(); expect(contentEl.parentElement).toHaveClass('callout-content'); });