From 749823aefa60a6325ce584ef2120496769ae0cde Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 8 Nov 2025 12:28:13 +0800 Subject: [PATCH] :necktie: Disabled preserve empty lines on the article posts --- app/components/Post/PostItem.vue | 9 +++-- app/composables/useMarkdownProcessor.ts | 44 ++++++++++++++----------- app/pages/posts/[...slug].vue | 14 ++++++-- 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/app/components/Post/PostItem.vue b/app/components/Post/PostItem.vue index 087b075..f9001d9 100644 --- a/app/components/Post/PostItem.vue +++ b/app/components/Post/PostItem.vue @@ -65,7 +65,11 @@ const emit = defineEmits<{ react: [symbol: string, attitude: number, delta: number] }>() -const { render } = useMarkdownProcessor() +const preserveEmptyLinesRef = ref(true) // New ref for the option + +const { render } = useMarkdownProcessor({ + preserveEmptyLines: preserveEmptyLinesRef +}) const htmlContent = ref("") @@ -74,8 +78,9 @@ function handleReaction(symbol: string, attitude: number, delta: number) { } watch( - props.item, + () => props.item, // Watch the item prop directly (value) => { + preserveEmptyLinesRef.value = value.type !== 1 // Update the ref if (value.content) htmlContent.value = render(value.content) }, { immediate: true, deep: true } diff --git a/app/composables/useMarkdownProcessor.ts b/app/composables/useMarkdownProcessor.ts index 6e0ca3e..c9ea46f 100644 --- a/app/composables/useMarkdownProcessor.ts +++ b/app/composables/useMarkdownProcessor.ts @@ -1,3 +1,4 @@ +import { computed, unref, type Ref } from "vue" import { createMarkdownExit, type PluginSimple, @@ -12,33 +13,38 @@ import katex from "katex" import "highlight.js/styles/a11y-dark.min.css" export function useMarkdownProcessor( - { preserveEmptyLines }: { preserveEmptyLines?: boolean } = { + options: { preserveEmptyLines?: boolean | Ref } = { preserveEmptyLines: true } ) { const serverUrl = useSolarNetworkUrl() - const processor = createMarkdownExit({ - breaks: true, - html: true, - linkify: true, - typographer: true - }) - // @ts-ignore - .use(texmath, { - engine: katex, - delimiters: "dollars", - katexOptions: { macros: { "\\RR": "\\mathbb{R}" } } - }) - .use(hljsMarkdown, { hljs }) - .use(imgSolarNetworkPlugin, { serverUrl: serverUrl }) + const processor = computed(() => { + const currentPreserveEmptyLines = unref(options.preserveEmptyLines) - if (preserveEmptyLines) { - processor.use(preserveEmptyLinesPlugin) - } + const md = createMarkdownExit({ + breaks: true, + html: true, + linkify: true, + typographer: true + }) + // @ts-ignore + .use(texmath, { + engine: katex, + delimiters: "dollars", + katexOptions: { macros: { "\\RR": "\\mathbb{R}" } } + }) + .use(hljsMarkdown, { hljs }) + .use(imgSolarNetworkPlugin, { serverUrl: serverUrl }) + + if (currentPreserveEmptyLines) { + md.use(preserveEmptyLinesPlugin) + } + return md + }) return { - render: (content: string) => processor.render(content) + render: (content: string) => processor.value.render(content) } } diff --git a/app/pages/posts/[...slug].vue b/app/pages/posts/[...slug].vue index 73a24d1..7d459b6 100644 --- a/app/pages/posts/[...slug].vue +++ b/app/pages/posts/[...slug].vue @@ -139,7 +139,7 @@