set up markdown

This commit is contained in:
MinamiFunakoshiTR 2025-03-10 11:27:28 -07:00
parent 8402b1fdbe
commit f1020c6161
Failed to extract signature
2 changed files with 18 additions and 29 deletions

View file

@ -1,15 +1,23 @@
The Markdown component renders markdown into HTML. That's it!
import { Meta, Canvas } from '@storybook/blocks';
---
import * as MarkdownStories from './Markdown.stories.svelte';
<Meta of={MarkdownStories} />
# Markdown
The `Markdown` component renders a markdown string into HTML.
```svelte
<script>
import { Markdown } from '@reuters-graphics/graphics-components';
</script>
<Markdown source="{'My markdown **string**!'}" />
<Markdown source={'My *awesome* text in **markdown**.'} />
```
<Canvas of={MarkdownStories.Demo} />
... well, almost.
Owing to a weird quirk of Svelte's [`@html`](https://svelte.dev/docs/special-tags#html) directive (see [this issue](https://github.com/reuters-graphics/graphics-components/issues/148)), if you want your resulting HTML to be dynamic — e.g., update after a SvelteKit app [hydrates](https://kit.svelte.dev/docs/glossary#hydration) — then you may need to set the included `$staticMarkdown` store to `false` in the browser.

View file

@ -1,35 +1,16 @@
<script module lang="ts">
// @ts-ignore raw
import componentDocs from './stories/docs/component.md?raw';
import { defineMeta } from '@storybook/addon-svelte-csf';
import Markdown from './Markdown.svelte';
import { withComponentDocs } from '$lib/docs/utils/withParams.js';
export const meta = {
const { Story } = defineMeta({
title: 'Components/Text elements/Markdown',
component: Markdown,
...withComponentDocs(componentDocs),
};
});
</script>
<script>
import { Template, Story } from '@storybook/addon-svelte-csf';
import Block from '../Block/Block.svelte';
</script>
<Template >
{#snippet children({ args })}
<Block>
<Markdown {...args} />
</Block>
{/snippet}
</Template>
<Story
name="Default"
args="{{
source: 'This is *some* text in **markdown**.',
}}"
name="Demo"
args={{
source: 'My *awesome* text in **markdown**.',
}}
/>