feat: fix rtl

This commit is contained in:
Alejandro Gómez
2025-12-10 15:47:38 +01:00
parent 10a486527c
commit b1be04cb39

View File

@@ -12,24 +12,23 @@ function hasRTLCharacters(text: string): boolean {
export function Text({ node }: TextNodeProps) {
const text = node.value;
// If no newlines, render as inline span
if (!text.includes("\n")) {
const isRTL = hasRTLCharacters(text);
return <span dir={isRTL ? "rtl" : "auto"}>{text || "\u00A0"}</span>;
}
// If has newlines, use spans with <br> tags
// If has newlines, use divs for proper RTL per line
const lines = text.split("\n");
return (
<>
{lines.map((line, idx) => {
const isRTL = hasRTLCharacters(line);
return (
<span key={idx}>
<span dir={isRTL ? "rtl" : "auto"}>{line || "\u00A0"}</span>
{idx < lines.length - 1 && <br />}
</span>
<div key={idx} dir={isRTL ? "rtl" : "auto"}>
{line || "\u00A0"}
</div>
);
})}
</>