👔 Disabled preserve empty lines on the article posts
This commit is contained in:
@@ -65,7 +65,11 @@ const emit = defineEmits<{
|
|||||||
react: [symbol: string, attitude: number, delta: number]
|
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<string>("")
|
const htmlContent = ref<string>("")
|
||||||
|
|
||||||
@@ -74,8 +78,9 @@ function handleReaction(symbol: string, attitude: number, delta: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
props.item,
|
() => props.item, // Watch the item prop directly
|
||||||
(value) => {
|
(value) => {
|
||||||
|
preserveEmptyLinesRef.value = value.type !== 1 // Update the ref
|
||||||
if (value.content) htmlContent.value = render(value.content)
|
if (value.content) htmlContent.value = render(value.content)
|
||||||
},
|
},
|
||||||
{ immediate: true, deep: true }
|
{ immediate: true, deep: true }
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { computed, unref, type Ref } from "vue"
|
||||||
import {
|
import {
|
||||||
createMarkdownExit,
|
createMarkdownExit,
|
||||||
type PluginSimple,
|
type PluginSimple,
|
||||||
@@ -12,13 +13,16 @@ import katex from "katex"
|
|||||||
import "highlight.js/styles/a11y-dark.min.css"
|
import "highlight.js/styles/a11y-dark.min.css"
|
||||||
|
|
||||||
export function useMarkdownProcessor(
|
export function useMarkdownProcessor(
|
||||||
{ preserveEmptyLines }: { preserveEmptyLines?: boolean } = {
|
options: { preserveEmptyLines?: boolean | Ref<boolean> } = {
|
||||||
preserveEmptyLines: true
|
preserveEmptyLines: true
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
const serverUrl = useSolarNetworkUrl()
|
const serverUrl = useSolarNetworkUrl()
|
||||||
|
|
||||||
const processor = createMarkdownExit({
|
const processor = computed(() => {
|
||||||
|
const currentPreserveEmptyLines = unref(options.preserveEmptyLines)
|
||||||
|
|
||||||
|
const md = createMarkdownExit({
|
||||||
breaks: true,
|
breaks: true,
|
||||||
html: true,
|
html: true,
|
||||||
linkify: true,
|
linkify: true,
|
||||||
@@ -33,12 +37,14 @@ export function useMarkdownProcessor(
|
|||||||
.use(hljsMarkdown, { hljs })
|
.use(hljsMarkdown, { hljs })
|
||||||
.use(imgSolarNetworkPlugin, { serverUrl: serverUrl })
|
.use(imgSolarNetworkPlugin, { serverUrl: serverUrl })
|
||||||
|
|
||||||
if (preserveEmptyLines) {
|
if (currentPreserveEmptyLines) {
|
||||||
processor.use(preserveEmptyLinesPlugin)
|
md.use(preserveEmptyLinesPlugin)
|
||||||
}
|
}
|
||||||
|
return md
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
render: (content: string) => processor.render(content)
|
render: (content: string) => processor.value.render(content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -139,7 +139,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from "vue"
|
import { computed, ref } from "vue" // Added ref
|
||||||
import { useMarkdownProcessor } from "~/composables/useMarkdownProcessor"
|
import { useMarkdownProcessor } from "~/composables/useMarkdownProcessor"
|
||||||
import type { SnPost } from "~/types/api"
|
import type { SnPost } from "~/types/api"
|
||||||
|
|
||||||
@@ -147,10 +147,14 @@ const route = useRoute()
|
|||||||
const slugParts = route.params.slug as string[]
|
const slugParts = route.params.slug as string[]
|
||||||
const id = slugParts.join("/")
|
const id = slugParts.join("/")
|
||||||
|
|
||||||
const { render } = useMarkdownProcessor()
|
|
||||||
|
|
||||||
const apiServer = useSolarNetwork()
|
const apiServer = useSolarNetwork()
|
||||||
|
|
||||||
|
const preserveEmptyLinesRef = ref(true) // New ref for the option
|
||||||
|
|
||||||
|
const { render } = useMarkdownProcessor({
|
||||||
|
preserveEmptyLines: preserveEmptyLinesRef
|
||||||
|
})
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: postData,
|
data: postData,
|
||||||
error,
|
error,
|
||||||
@@ -159,6 +163,10 @@ const {
|
|||||||
try {
|
try {
|
||||||
const resp = await apiServer(`/sphere/posts/${id}`)
|
const resp = await apiServer(`/sphere/posts/${id}`)
|
||||||
const post = resp as SnPost
|
const post = resp as SnPost
|
||||||
|
|
||||||
|
// Update the ref based on post.type
|
||||||
|
preserveEmptyLinesRef.value = post.type !== 1
|
||||||
|
|
||||||
let html = ""
|
let html = ""
|
||||||
if (post.content) {
|
if (post.content) {
|
||||||
html = render(post.content)
|
html = render(post.content)
|
||||||
|
|||||||
Reference in New Issue
Block a user