misc: fix spoiler support

This commit is contained in:
Xylight committed 2024-08-02 12:28:28 -07:00
1 parent 98a899c596
commit 687bcde97b
4 files changed
+5 -7

No files matched your search

@@ -80,5 +80,6 @@
options={{
pedantic: true,
}}
isInline={inline}
/>
</div>
@@ -1,5 +1,5 @@
<script lang="ts">
import { Disclosure } from 'mono-svelte'
import { marked } from 'marked'
export let raw: string
@@ -7,7 +7,7 @@
const spoilerRegex = /^::: spoiler (.+)\n([\s\S]+?)\n:::/gm
return text.replace(spoilerRegex, function (match, title, content) {
return `<details><summary class="cursor-pointer">${title}</summary>${content}</details>`
return `<details><summary class="cursor-pointer">${marked.parseInline(title)}</summary>${marked.parse(content)}</details>`
})
}
@@ -1,14 +1,11 @@
<script lang="ts">
export let text: string
export let raw: string
console.log(raw)
function preprocess(src: string): string {
// superscript, subscript support
src = src
.replace(/~([^~]+)~/g, '<sub>$1</sub>')
.replace(/\^([^^]+)\^/g, '<sup>$1</sup>')
.replaceAll(/~([^~]+)~/g, '<sub>$1</sub>')
.replaceAll(/\^([^^]+)\^/g, '<sup>$1</sup>')
return src
}