build fix

This commit is contained in:
alma 2025-05-05 19:08:28 +02:00
parent 27a729f986
commit e280e2bce1

View File

@ -67,28 +67,65 @@ export function applyTextDirection(htmlContent: string, textContent?: string): s
* Process content to determine direction and return direction-enhanced HTML
*
* @param content Content to process (HTML or plain text)
* @returns Object containing processed HTML and detected direction
* @returns Object containing processed HTML, plain text, and detected direction
*/
export function processContentWithDirection(content: string | undefined): { html: string; direction: 'ltr' | 'rtl' } {
export function processContentWithDirection(content: string | undefined | { html?: string; text?: string }): {
html: string;
text: string;
direction: 'ltr' | 'rtl'
} {
if (!content) {
return { html: '', direction: 'ltr' };
return { html: '', text: '', direction: 'ltr' };
}
// Extract text from the content for direction detection
const textContent = content.replace(/<[^>]*>/g, '')
.replace(/&nbsp;/g, ' ')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&amp;/g, '&');
let htmlContent = '';
let textContent = '';
// Handle different content types
if (typeof content === 'string') {
// String content might be HTML or plain text
if (content.includes('<') && (content.includes('<html') || content.includes('<body') || content.includes('<div'))) {
htmlContent = content;
textContent = content.replace(/<[^>]*>/g, '')
.replace(/&nbsp;/g, ' ')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&amp;/g, '&');
} else {
// It's plain text
textContent = content;
// Create simple HTML from the plain text (preserve whitespace)
htmlContent = content.replace(/\n/g, '<br>').replace(/\s\s/g, ' &nbsp;');
}
} else {
// It's an object with html and/or text properties
htmlContent = content.html || '';
textContent = content.text || '';
// If we have HTML but no text, extract text from HTML
if (htmlContent && !textContent) {
textContent = htmlContent.replace(/<[^>]*>/g, '')
.replace(/&nbsp;/g, ' ')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&amp;/g, '&');
}
// If we have text but no HTML, create simple HTML from the text
if (textContent && !htmlContent) {
htmlContent = textContent.replace(/\n/g, '<br>').replace(/\s\s/g, ' &nbsp;');
}
}
// Detect the direction of the text
const direction = detectTextDirection(textContent);
// Apply the direction to the HTML content
const directionEnhancedHtml = applyTextDirection(content, textContent);
const directionEnhancedHtml = applyTextDirection(htmlContent, textContent);
return {
html: directionEnhancedHtml,
text: textContent,
direction
};
}