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

Support embedded HTML in markdown #88

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion src/lib/components/markdown/Fallback.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import remarkRehype from "remark-rehype";
import { unified } from "unified";

const processor = unified().use(remarkRehype).use(rehypeStringify);
const processor = unified().use(remarkRehype, { allowDangerousHtml: true }).use(rehypeStringify, { allowDangerousHtml: true });
</script>

<script lang="ts">
Expand Down
22 changes: 22 additions & 0 deletions src/lib/md.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,25 @@
.prose p img {
@apply inline;
}

.prose details {
list-style-position: outside;
@apply overflow-hidden rounded px-4 py-3 ring-1 ring-neutral/20 transition-background-color;
}

.prose details[open] > summary {
@apply mb-3 ring-(1 neutral/20);
}

.prose summary {
list-style: none;
@apply flex flex-row items-center justify-between px-4 py-3 -mx-4 -my-3 after:content-[''];
}

.prose summary::after {
@apply i-humbleicons-expand text-neutral/50 transition-color;
}

.prose summary:hover::after {
@apply text-neutral/80;
}
8 changes: 8 additions & 0 deletions src/routes/test/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
import text from "./example.md?raw";
import BaseMarkdown from "$lib/components/markdown/BaseMarkdown.svelte";
</script>

<div class="mx-auto my-10 w-lg rounded bg-white/5 p-5">
<BaseMarkdown {text} />
</div>
30 changes: 30 additions & 0 deletions src/routes/test/example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Markdown inside HTML

Markdown lists should be inside `<tetails>` tag.

<details open>
<summary>
title
</summary>
text
- 1
- 2
- 3

> This is a test

## First

1. abc
2. def
3. ghi
4. jkl

## Second

- mno
- pqr
- stu
- vwx

</details>
Loading