[FA-misc] Should fix paragraph blocking
All checks were successful
CI / build-backend (pull_request) Successful in 1m21s
CI / build-frontend (pull_request) Successful in 39s

This commit is contained in:
gamer147
2025-12-10 13:40:33 -05:00
parent f830773af5
commit 4fb34bdef7
2 changed files with 33 additions and 4 deletions

View File

@@ -155,10 +155,9 @@
<Card>
<CardContent class="px-6 py-8 md:px-12">
<article
class="prose prose-lg dark:prose-invert mx-auto max-w-none whitespace-pre-line
prose-p:text-foreground prose-p:mb-4 prose-p:leading-relaxed
class="prose prose-lg dark:prose-invert mx-auto max-w-none
prose-headings:text-foreground
first:prose-p:mt-0 last:prose-p:mb-0"
[&>p]:text-foreground [&>p]:mb-6 [&>p]:leading-relaxed"
>
{@html sanitizedBody}
</article>

View File

@@ -1,12 +1,42 @@
import DOMPurify from 'isomorphic-dompurify';
/**
* Splits plain text into paragraphs based on newlines.
* Double newlines create new paragraphs, single newlines become <br>.
* If the content already contains HTML block elements, returns as-is.
*/
function wrapInParagraphs(text: string): string {
// Check if content already has block-level HTML elements
const hasBlockElements = /<(p|div|h[1-6]|ul|ol|blockquote|pre|table|hr)[>\s]/i.test(text);
if (hasBlockElements) {
return text;
}
// Split on double newlines (paragraph breaks)
const paragraphs = text.split(/\n\s*\n/);
return paragraphs
.map((para) => {
const trimmed = para.trim();
if (!trimmed) return '';
// Convert single newlines to <br> within paragraphs
const withBreaks = trimmed.replace(/\n/g, '<br>');
return `<p>${withBreaks}</p>`;
})
.filter(Boolean)
.join('\n');
}
/**
* Sanitizes chapter HTML content with extended allowed tags.
* More permissive than the description sanitizer to support
* formatted novel content including headings, lists, and images.
* Also wraps plain text in paragraph tags for better browser translate support.
*/
export function sanitizeChapterHtml(html: string): string {
return DOMPurify.sanitize(html, {
// First wrap in paragraphs if needed, then sanitize
const wrapped = wrapInParagraphs(html);
return DOMPurify.sanitize(wrapped, {
ALLOWED_TAGS: [
// Basic formatting
'b',