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
+29 -10

No files matched your search

+7 -3
View File
@@ -8,6 +8,7 @@
import PostLink from '$lib/components/lemmy/post/PostLink.svelte' import PostLink from '$lib/components/lemmy/post/PostLink.svelte'
import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte' import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte'
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js' import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
import Markdown from '$lib/components/markdown/Markdown.svelte'
export let post: PostView export let post: PostView
export let actions: boolean = true export let actions: boolean = true
@@ -102,14 +103,17 @@
/> />
{/if} {/if}
{#if post.post.body && !post.post.nsfw} {#if post.post.body && !post.post.nsfw}
<p <div
class="text-sm bg-slate-100 dark:bg-zinc-800 class="text-sm bg-slate-100 dark:bg-zinc-800
border border-slate-200 dark:border-zinc-700 rounded-md p-2" border border-slate-200 dark:border-zinc-700 rounded-md p-2"
> >
{post.post.body.length > 350 <Markdown
inline
source={post.post.body.length > 350
? `${post.post.body.slice(0, 350)}...` ? `${post.post.body.slice(0, 350)}...`
: post.post.body} : post.post.body}
</p> />
</div>
{/if} {/if}
{/if} {/if}
{#if actions} {#if actions}
+19 -6
View File
@@ -22,12 +22,25 @@ export const md = new MarkdownIt({
}, },
}) })
export const mdInline: MarkdownIt = new MarkdownIt('zero').enable([ export const mdInline: MarkdownIt = new MarkdownIt('zero')
'emphasis', .enable(['emphasis', 'backticks', 'strikethrough', 'link'])
'backticks', .use(markdown_it_container, 'spoiler', {
'strikethrough', validate: (params: string) => {
'link', 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('!', { md.linkify.add('!', {
validate: function (text, pos, self) { validate: function (text, pos, self) {
+3 -1
View File
@@ -53,7 +53,9 @@
<span class:hidden={!expanded}>Frontpage</span> <span class:hidden={!expanded}>Frontpage</span>
</Button> </Button>
{#if $user} {#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 <Button
class="hover:bg-slate-200 {expanded ? '' : '!p-1.5'}" class="hover:bg-slate-200 {expanded ? '' : '!p-1.5'}"
color="tertiary" color="tertiary"