fix: 🐛 fix collapsed callout syntax rendering as blockquote
This commit is contained in:
parent
e3fb92508f
commit
68b65ab0e0
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
## [2022-08-07]
|
## [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: 🐛 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).
|
- fix: 🐛 code blocks no longer render as "undefined" for unregistered languages (e.g. Dataview or Toggl query blocks).
|
||||||
|
|
||||||
|
@ -12,10 +12,10 @@
|
|||||||
|
|
||||||
$: if (content) {
|
$: if (content) {
|
||||||
const titleElement = content.getElementsByTagName('p')[0];
|
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) {
|
if (match) {
|
||||||
type = match[1]?.trim();
|
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)}`;
|
color = `--${getCalloutColor(type)}`;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
export let raw: string;
|
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;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if isCallout}
|
{#if isCallout}
|
||||||
|
@ -2,19 +2,52 @@ import { render, screen } from '@testing-library/svelte';
|
|||||||
import { readMd } from './util';
|
import { readMd } from './util';
|
||||||
import MarkdownRenderer from '$lib/components/MarkdownRenderer.svelte';
|
import MarkdownRenderer from '$lib/components/MarkdownRenderer.svelte';
|
||||||
|
|
||||||
describe('Rendering callouts', async () => {
|
const testCases = [
|
||||||
const plaintext = await readMd('callout.md');
|
{
|
||||||
|
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 () => {
|
it('Renders callout title correctly ', async () => {
|
||||||
render(MarkdownRenderer, { plaintext: plaintext });
|
render(MarkdownRenderer, { plaintext: testCase.markdown });
|
||||||
const titleEl = await screen.findByText('Don!t forget to account for non-letters! //fsd \\n');
|
const titleEl = await screen.findByText(testCase.title);
|
||||||
expect(titleEl).toBeInTheDocument();
|
expect(titleEl).toBeInTheDocument();
|
||||||
expect(titleEl).toHaveClass('callout-title');
|
expect(titleEl).toHaveClass('callout-title');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Renders callout content correctly ', async () => {
|
it('Renders callout content correctly ', async () => {
|
||||||
render(MarkdownRenderer, { plaintext: plaintext });
|
render(MarkdownRenderer, { plaintext: testCase.markdown });
|
||||||
const contentEl = await screen.findByText('Sample text.');
|
const contentEl = await screen.findByText(testCase.content);
|
||||||
expect(contentEl).toBeInTheDocument();
|
expect(contentEl).toBeInTheDocument();
|
||||||
expect(contentEl.parentElement).toHaveClass('callout-content');
|
expect(contentEl.parentElement).toHaveClass('callout-content');
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user