misc: re-add markdown to posts

This commit is contained in:
Xyphyn committed 2023-07-31 13:00:35 -07:00
1 parent 715c8f878b
commit b4bcadf40d
3 files changed
+31 -12

No files matched your search

+9 -5
View File
@@ -8,6 +8,7 @@
import PostLink from '$lib/components/lemmy/post/PostLink.svelte'
import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte'
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
import Markdown from '$lib/components/markdown/Markdown.svelte'
export let post: PostView
export let actions: boolean = true
@@ -102,14 +103,17 @@
/>
{/if}
{#if post.post.body && !post.post.nsfw}
<p
<div
class="text-sm bg-slate-100 dark:bg-zinc-800
border border-slate-200 dark:border-zinc-700 rounded-md p-2"
>
{post.post.body.length > 350
? `${post.post.body.slice(0, 350)}...`
: post.post.body}
</p>
<Markdown
inline
source={post.post.body.length > 350
? `${post.post.body.slice(0, 350)}...`
: post.post.body}
/>
</div>
{/if}
{/if}
{#if actions}
+19 -6
View File
@@ -22,12 +22,25 @@ export const md = new MarkdownIt({
},
})
export const mdInline: MarkdownIt = new MarkdownIt('zero').enable([
'emphasis',
'backticks',
'strikethrough',
'link',
])
export const mdInline: MarkdownIt = new MarkdownIt('zero')
.enable(['emphasis', 'backticks', 'strikethrough', 'link'])
.use(markdown_it_container, 'spoiler', {
validate: (params: string) => {
return params.trim().match(/^spoiler+(.*)/)
},
render: (tokens: any, idx: any) => {
var m = tokens[idx].info.trim().match(/^spoiler+(.*)/)
if (tokens[idx].nesting === 1) {
// opening tag
return `<details><summary> ${md.utils.escapeHtml(m[1])} </summary>\n`
} else {
// closing tag
return '</details>\n'
}
},
})
md.linkify.add('!', {
validate: function (text, pos, self) {
+3 -1
View File
@@ -53,7 +53,9 @@
<span class:hidden={!expanded}>Frontpage</span>
</Button>
{#if $user}
{#each $user.follows.map((f) => f.community) as follow}
{#each $user.follows
.map((f) => f.community)
.sort((a, b) => a.title.localeCompare(b.title)) as follow}
<Button
class="hover:bg-slate-200 {expanded ? '' : '!p-1.5'}"
color="tertiary"