misc: add markdown to body preview
This commit is contained in:
1 parent
17316b8cdf
commit
ba6fc8cbeb
4 files changed
+19
-6
No files matched your search
@@ -10,6 +10,7 @@
|
|||||||
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
||||||
import PostForm from '$lib/components/lemmy/post/PostForm.svelte'
|
import PostForm from '$lib/components/lemmy/post/PostForm.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
|
||||||
|
|
||||||
@@ -108,10 +109,15 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{#if post.post.body && !post.post.nsfw}
|
{#if post.post.body && !post.post.nsfw}
|
||||||
<p
|
<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"
|
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>
|
</p>
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { md } from '$lib/components/markdown/markdown'
|
import { md, mdInline } from '$lib/components/markdown/markdown'
|
||||||
|
|
||||||
export let source: string = ''
|
export let source: string = ''
|
||||||
|
export let inline: boolean = false
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="break-words flex flex-col markdown gap-2 leading-[1.5]">
|
<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>
|
</div>
|
||||||
|
|
||||||
<style lang="postcss">
|
<style lang="postcss">
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ export const md = new MarkdownIt({
|
|||||||
},
|
},
|
||||||
|
|
||||||
render: (tokens: any, idx: any) => {
|
render: (tokens: any, idx: any) => {
|
||||||
console.log('test')
|
|
||||||
var m = tokens[idx].info.trim().match(/^spoiler+(.*)/)
|
var m = tokens[idx].info.trim().match(/^spoiler+(.*)/)
|
||||||
|
|
||||||
if (tokens[idx].nesting === 1) {
|
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',
|
'emphasis',
|
||||||
'backticks',
|
'backticks',
|
||||||
'strikethrough',
|
'strikethrough',
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
export default {
|
export default {
|
||||||
content: ['src/**/*.{js,ts,svelte,html}'],
|
content: ['src/**/*.{js,ts,svelte,html}'],
|
||||||
theme: {
|
theme: {
|
||||||
|
fontFamily: {
|
||||||
|
'sans': ['Cantarell', 'system-ui']
|
||||||
|
},
|
||||||
extend: {
|
extend: {
|
||||||
animation: {
|
animation: {
|
||||||
'pop-in': 'pop-in 0.25s ease-out forwards'
|
'pop-in': 'pop-in 0.25s ease-out forwards'
|
||||||
|
|||||||
Reference in new issue
Block a user