preview - work in progress

This commit is contained in:
Anton Tranelis 2025-06-19 08:46:11 +02:00
parent 4240a2bbbd
commit 25aa60983f
2 changed files with 5 additions and 59 deletions

View File

@ -1,9 +1,3 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/restrict-plus-operands */
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-call */
import { RichTextEditor } from '#components/Input/RichTextEditor/RichTextEditor'
import { fixUrls, mailRegex } from '#utils/ReplaceURLs'
@ -36,7 +30,7 @@ export const TextView = ({
innerText = text
}
if (innerText && truncate) innerText = truncateText(removeMarkdownKeepParagraphs(innerText), 100)
if (innerText && truncate) innerText = truncateMarkdown(innerText, 100)
if (innerText) replacedText = fixUrls(innerText)
@ -49,54 +43,6 @@ export const TextView = ({
return <RichTextEditor defaultValue={replacedText} readOnly={true} />
}
function removeMarkdownKeepParagraphs(text: string): string {
return (
text
// 1) Bilder entfernen
.replace(/!\[.*?\]\(.*?\)/g, '')
// 2) Markdown-Links [Text](URL) → URL
.replace(/\[.*?\]\(\s*(https?:\/\/[^\s)]+)\s*\)/g, '$1')
// 3) Autolinks <http://…> → http://…
.replace(/<\s*(https?:\/\/[^\s>]+)\s*>/g, '$1')
// 4) Code-Fences und Inline-Code entfernen
.replace(/```[\s\S]*?```/g, '')
.replace(/`([^`]+)`/g, '$1')
// 8) Tabellen-Pipes entfernen
.replace(/^\|(.+)\|$/gm, '$1')
.replace(/^\s*\|[-\s|]+\|$/gm, '')
// 9) Blockquotes
.replace(/^>\s+(.*)$/gm, '$1')
// 10) Echte HTML-Tags (außer Absätze) entfernen
.replace(/<(?!\s*\/?\s*p\s*>)[^>]+>/g, '')
// 11) Zeilenumbrüche normalisieren
.replace(/\r\n|\r/g, '\n')
// 12) Mehrfache Leerzeilen auf max. 2 reduzieren
.replace(/\n{3,}/g, '\n\n')
// 13) Trim
.trim()
)
}
function truncateText(text, limit) {
if (text.length <= limit) {
return text
}
let truncated = ''
let length = 0
// Split the text by paragraphs
const paragraphs = text.split('\n')
for (const paragraph of paragraphs) {
if (length + paragraph.length > limit) {
truncated += paragraph.slice(0, limit - length) + '...'
break
} else {
truncated += paragraph + '\n'
length += paragraph.length
}
}
return truncated.trim()
export function truncateMarkdown(markdown: string, limit: number): string {
return markdown.slice(0, limit)
}

View File

@ -157,8 +157,8 @@ export const OverlayItemsIndexPage = ({
: 0
return dateB - dateA // Subtracts milliseconds which are numbers
})
.map((i, k) => (
<div key={k} className='tw:break-inside-avoid tw:mb-6'>
.map((i) => (
<div key={i.id} className='tw:break-inside-avoid tw:mb-6'>
<ItemCard
i={i}
loading={loading}