style: modified returned markdown to be more user-friendly.
This commit is contained in:
parent
579045d933
commit
c9676e17a7
|
|
@ -9,7 +9,7 @@ const props = defineProps<{
|
||||||
|
|
||||||
// Initialize Markdown parser
|
// Initialize Markdown parser
|
||||||
const md = new MarkdownIt({
|
const md = new MarkdownIt({
|
||||||
breaks: true, // Support line breaks
|
breaks: false, // Support line breaks
|
||||||
linkify: true, // Make URLs clickable
|
linkify: true, // Make URLs clickable
|
||||||
html: false // Prevent raw HTML injection
|
html: false // Prevent raw HTML injection
|
||||||
})
|
})
|
||||||
|
|
@ -17,7 +17,11 @@ const md = new MarkdownIt({
|
||||||
// Removes all the h1,h2,h3 to make the Md more user friendly
|
// Removes all the h1,h2,h3 to make the Md more user friendly
|
||||||
const cleanMarkdown = (markdown: string): string => {
|
const cleanMarkdown = (markdown: string): string => {
|
||||||
if (!markdown) return ''
|
if (!markdown) return ''
|
||||||
return markdown.replace(/^#{1,3}\s(.*)$/gm, '#### $1')
|
return markdown
|
||||||
|
.replace(/\r\n/g, '\n') // normalize Windows line endings
|
||||||
|
.replace(/([.!?])(\s+)(?=[A-Z])/g, '$1\n') // insert line break after sentence-ending punctuation
|
||||||
|
.replace(/\n{3,}/g, '\n\n') // squash triple+ line breaks
|
||||||
|
.replace(/^#{1,3}\s(.*)$/gm, '#### $1') // downgrade headings
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute parsed content
|
// Compute parsed content
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user