From 27a729f986e298b94b2f5ede73c344be24cf89be Mon Sep 17 00:00:00 2001 From: alma Date: Mon, 5 May 2025 17:57:14 +0200 Subject: [PATCH] build fix --- lib/utils/text-direction.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/utils/text-direction.ts b/lib/utils/text-direction.ts index 071dd4f9..b198dd06 100644 --- a/lib/utils/text-direction.ts +++ b/lib/utils/text-direction.ts @@ -61,4 +61,34 @@ export function applyTextDirection(htmlContent: string, textContent?: string): s // Otherwise, wrap the content with a direction-aware container return `
${htmlContent}
`; +} + +/** + * 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 + */ +export function processContentWithDirection(content: string | undefined): { html: string; direction: 'ltr' | 'rtl' } { + if (!content) { + return { html: '', direction: 'ltr' }; + } + + // Extract text from the content for direction detection + const textContent = content.replace(/<[^>]*>/g, '') + .replace(/ /g, ' ') + .replace(/</g, '<') + .replace(/>/g, '>') + .replace(/&/g, '&'); + + // Detect the direction of the text + const direction = detectTextDirection(textContent); + + // Apply the direction to the HTML content + const directionEnhancedHtml = applyTextDirection(content, textContent); + + return { + html: directionEnhancedHtml, + direction + }; } \ No newline at end of file