fix: spoiler support
This commit is contained in:
1 parent
687bcde97b
commit
14789bd5ba
7 files changed
+85
-60
No files matched your search
@@ -9,7 +9,6 @@
|
||||
code: string
|
||||
lang?: string
|
||||
} {
|
||||
console.log(raw)
|
||||
const match = /^```(.*)/gi.exec(src)
|
||||
|
||||
if (match?.[1]) {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="max-w-full h-auto rounded-2xl p-2 border border-slate-200 dark:border-zinc-800
|
||||
class="max-w-xl h-auto rounded-2xl p-2 border border-slate-200 dark:border-zinc-800
|
||||
inline-block"
|
||||
>
|
||||
{#if type == 'video' || type == 'embed' || type == 'iframe'}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<p>
|
||||
<p class="leading-[1.5]">
|
||||
<slot />
|
||||
</p>
|
||||
@@ -1,17 +1,37 @@
|
||||
<script lang="ts">
|
||||
import { marked } from 'marked'
|
||||
import SvelteMarkdown from 'svelte-markdown'
|
||||
import { options, renderers } from '../Markdown.svelte'
|
||||
import { Disclosure } from 'mono-svelte'
|
||||
import { Icon } from 'svelte-hero-icons'
|
||||
import Expandable from '$lib/components/ui/Expandable.svelte'
|
||||
|
||||
export let raw: string
|
||||
|
||||
function extractTitle(text: string) {
|
||||
const spoilerRegex = /^::: spoiler (.+)\n([\s\S]+?)\n:::/gm
|
||||
const spoilerRegex = /^::: ?spoiler (.+)\n([\s\S]+?)\n:::/gm
|
||||
const result = spoilerRegex.exec(text)
|
||||
|
||||
return text.replace(spoilerRegex, function (match, title, content) {
|
||||
return `<details><summary class="cursor-pointer">${marked.parseInline(title)}</summary>${marked.parse(content)}</details>`
|
||||
})
|
||||
if (!result?.[1] || !result?.[2])
|
||||
return {
|
||||
title: 'parsing error',
|
||||
content: 'parsing error',
|
||||
}
|
||||
|
||||
return {
|
||||
title: result[1],
|
||||
content: result[2],
|
||||
}
|
||||
}
|
||||
|
||||
$: html = extractTitle(raw)
|
||||
$: data = extractTitle(raw)
|
||||
|
||||
$: console.log(data.content)
|
||||
</script>
|
||||
|
||||
{@html html}
|
||||
<Expandable class="border-y border-slate-200 dark:border-zinc-800 py-2">
|
||||
<div slot="title" class="text-left">
|
||||
<SvelteMarkdown source={data.title} {renderers} {options} isInline />
|
||||
</div>
|
||||
<SvelteMarkdown source={data.content} {renderers} {options} />
|
||||
</Expandable>
|
||||
Reference in new issue
Block a user