misc: add markdown to body preview

This commit is contained in:
Xyphyn committed 2023-07-29 12:40:06 -07:00
1 parent 17316b8cdf
commit ba6fc8cbeb
4 files changed
+19 -6

No files matched your search

+8 -2
View File
@@ -10,6 +10,7 @@
import Modal from '$lib/components/ui/modal/Modal.svelte'
import PostForm from '$lib/components/lemmy/post/PostForm.svelte'
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
import Markdown from '$lib/components/markdown/Markdown.svelte'
export let post: PostView
@@ -108,10 +109,15 @@
{/if}
{#if post.post.body && !post.post.nsfw}
<p
class="text-sm max-h-[74px] line-clamp-3 bg-slate-100 dark:bg-zinc-800
class="text-sm line-clamp-3 bg-slate-100 dark:bg-zinc-800
border border-slate-200 dark:border-zinc-700 rounded-md p-2"
>
{post.post.body}
<Markdown
inline
source={post.post.body.length > 200
? `${post.post.body.slice(0, 200)}...`
: post.post.body}
/>
</p>
{/if}
{/if}
+7 -2
View File
@@ -1,11 +1,16 @@
<script lang="ts">
import { md } from '$lib/components/markdown/markdown'
import { md, mdInline } from '$lib/components/markdown/markdown'
export let source: string = ''
export let inline: boolean = false
</script>
<div class="break-words flex flex-col markdown gap-2 leading-[1.5]">
{@html md.render(source)}
{#if inline}
{@html mdInline.render(source)}
{:else}
{@html md.render(source)}
{/if}
</div>
<style lang="postcss">
+1 -2
View File
@@ -10,7 +10,6 @@ export const md = new MarkdownIt({
},
render: (tokens: any, idx: any) => {
console.log('test')
var m = tokens[idx].info.trim().match(/^spoiler+(.*)/)
if (tokens[idx].nesting === 1) {
@@ -23,7 +22,7 @@ export const md = new MarkdownIt({
},
})
export const mdLimited: MarkdownIt = new MarkdownIt('zero').enable([
export const mdInline: MarkdownIt = new MarkdownIt('zero').enable([
'emphasis',
'backticks',
'strikethrough',
+3
View File
@@ -2,6 +2,9 @@
export default {
content: ['src/**/*.{js,ts,svelte,html}'],
theme: {
fontFamily: {
'sans': ['Cantarell', 'system-ui']
},
extend: {
animation: {
'pop-in': 'pop-in 0.25s ease-out forwards'