fix: markdown crash
This commit is contained in:
1 parent
8eaa13b5e8
commit
ef8bb93d53
1 file changed
+13
-8
@@ -7,11 +7,9 @@
|
|||||||
|
|
||||||
function replaceURLs(node: HTMLElement, source: string) {
|
function replaceURLs(node: HTMLElement, source: string) {
|
||||||
if (!div) return
|
if (!div) return
|
||||||
console.log('replacing source', source)
|
|
||||||
const links = node.querySelectorAll('a')
|
const links = node.querySelectorAll('a')
|
||||||
|
|
||||||
links.forEach((l) => {
|
links.forEach((l) => {
|
||||||
console.log('replacing link', l.href)
|
|
||||||
const photonified = photonify(l.href)
|
const photonified = photonify(l.href)
|
||||||
if (photonified) l.href = photonified
|
if (photonified) l.href = photonified
|
||||||
})
|
})
|
||||||
@@ -19,18 +17,25 @@
|
|||||||
|
|
||||||
let div: HTMLElement
|
let div: HTMLElement
|
||||||
|
|
||||||
$: replaceURLs(div, source)
|
const render = (source: string): string => {
|
||||||
|
if (!source || source == '') return ''
|
||||||
|
|
||||||
|
try {
|
||||||
|
return inline ? mdInline.render(source) : md.render(source)
|
||||||
|
} catch (err) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: rendered = render(source)
|
||||||
|
$: replaceURLs(div, rendered)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
bind:this={div}
|
bind:this={div}
|
||||||
class="break-words flex flex-col markdown gap-2 leading-[1.5]"
|
class="break-words flex flex-col markdown gap-2 leading-[1.5]"
|
||||||
>
|
>
|
||||||
{#if inline}
|
{@html rendered}
|
||||||
{@html mdInline.render(source)}
|
|
||||||
{:else}
|
|
||||||
{@html md.render(source)}
|
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style lang="postcss">
|
<style lang="postcss">
|
||||||
|
|||||||
Reference in new issue
Block a user