Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: render announcements as markdown #180

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/lib/components/announcements/AnnouncementRow.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import { AnnouncementImportance } from '$lib/generated';
import { markdown } from '$lib/utils/markdown';

const iconNames: { [key in AnnouncementImportance]: string } = {
[AnnouncementImportance.Info]: 'info',
Expand Down Expand Up @@ -27,10 +28,14 @@
<div class="striped p-1 text-black">
<span class="material-icons align-middle text-2xl">{iconNames[importance]}</span>
<div
class="text-l inline-block max-w-full break-words align-middle"
class="text-l announcement-markdown inline-block max-w-full break-words align-middle"
class:font-mono={isMonospace}
class:whitespace-pre={isMonospace}>
<b>{importance}: </b>{finalMessage}
<b>{importance}: </b>
{#await markdown(finalMessage, true) then previewRendered}
<!-- eslint-disable-next-line -->
{@html previewRendered}
{/await}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/versions/VersionForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
<div class="grid grid-flow-row auto-rows-max gap-2">
<span>{$t('preview')}:</span>
{#await markdown(preview) then previewRendered}
<!-- eslint-disable -->
<!-- eslint-disable-next-line -->
<div class="markdown-content right">{@html previewRendered}</div>
{/await}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/utils/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ if (!browser) {
resolver(DOMPurify.sanitize);
}

export const markdown = (md: string): Promise<string> =>
export const markdown = (md: string, inline = false): Promise<string> =>
sanitizer.then((s) => {
const sanitized = s(marked(md));
const sanitized = s(inline ? marked.parseInline(md) : marked(md));
const parsed = new DOMParser().parseFromString(sanitized, 'text/html');
Prism.highlightAllUnder(parsed.body);
return parsed.body.innerHTML;
Expand Down
6 changes: 6 additions & 0 deletions src/routes/_global.postcss
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ body.accessibility {
}
}

.announcement-markdown {
& a {
text-decoration: underline;
}
}

@font-face {
font-family: Flow;
font-weight: 400;
Expand Down
Loading