diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser/html/CssEncoder.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser/html/CssEncoder.kt index 01b3e85f..db31a716 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser/html/CssEncoder.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser/html/CssEncoder.kt @@ -140,10 +140,14 @@ internal object CssEncoder { * @param cssStyleMap the CSS style map to convert. * @return the converted [ParagraphStyle]. */ - internal fun parseCssStyleMapToParagraphStyle(cssStyleMap: Map): ParagraphStyle { + internal fun parseCssStyleMapToParagraphStyle( + cssStyleMap: Map, + attributes: Map + ): ParagraphStyle { + val direction = cssStyleMap["direction"] ?: attributes["dir"] return ParagraphStyle( textAlign = cssStyleMap["text-align"]?.let { parseCssTextAlign(it) } ?: TextAlign.Unspecified, - textDirection = cssStyleMap["direction"]?.let { parseCssTextDirection(it) } ?: TextDirection.Unspecified, + textDirection = direction?.let { parseCssTextDirection(it) } ?: TextDirection.Unspecified, lineHeight = cssStyleMap["line-height"]?.let { parseCssLineHeight(it) } ?: TextUnit.Unspecified, textIndent = cssStyleMap["text-indent"]?.let { parseCssTextIndent(it) }, ) diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser/html/RichTextStateHtmlParser.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser/html/RichTextStateHtmlParser.kt index a497a635..5c4328e1 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser/html/RichTextStateHtmlParser.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser/html/RichTextStateHtmlParser.kt @@ -105,7 +105,7 @@ internal object RichTextStateHtmlParser : RichTextStateParser { val paragraphType = encodeHtmlElementToRichParagraphType(lastOpenedTag) currentRichParagraph.type = paragraphType - val cssParagraphStyle = CssEncoder.parseCssStyleMapToParagraphStyle(cssStyleMap) + val cssParagraphStyle = CssEncoder.parseCssStyleMapToParagraphStyle(cssStyleMap, attributes) currentRichParagraph.paragraphStyle = currentRichParagraph.paragraphStyle.merge(cssParagraphStyle) } @@ -120,7 +120,7 @@ internal object RichTextStateHtmlParser : RichTextStateParser { if (name == "li" && lastOpenedTag != null) { paragraphType = encodeHtmlElementToRichParagraphType(lastOpenedTag) } - val cssParagraphStyle = CssEncoder.parseCssStyleMapToParagraphStyle(cssStyleMap) + val cssParagraphStyle = CssEncoder.parseCssStyleMapToParagraphStyle(cssStyleMap, attributes) newRichParagraph.paragraphStyle = newRichParagraph.paragraphStyle.merge(cssParagraphStyle) newRichParagraph.type = paragraphType diff --git a/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/parser/html/CssEncoderTest.kt b/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/parser/html/CssEncoderTest.kt index 29104b5f..ecc30036 100644 --- a/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/parser/html/CssEncoderTest.kt +++ b/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/parser/html/CssEncoderTest.kt @@ -382,4 +382,15 @@ class CssEncoderTest { CssEncoder.parseCssTextIndent(textIndent4), ) } + + @Test + fun testParseCssStyleMapToParagraphStyle() { + val paragraphStyle = CssEncoder.parseCssStyleMapToParagraphStyle( + cssStyleMap = mapOf("direction" to "ltr"), + attributes = mapOf("dir" to "rtl") + ) + + assertEquals(TextDirection.Ltr, paragraphStyle.textDirection) + } + } \ No newline at end of file