Skip to content

Commit

Permalink
add test to parseCssStyleMapToParagraphStyle function to that check t…
Browse files Browse the repository at this point in the history
…ext direction
  • Loading branch information
dhiaspaner committed Jan 7, 2025
1 parent 12b2062 commit ecdb801
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ internal object CssEncoder {
* @param cssStyleMap the CSS style map to convert.
* @return the converted [ParagraphStyle].
*/
internal fun parseCssStyleMapToParagraphStyle(cssStyleMap: Map<String, String>,attributes: Map<String,String>): ParagraphStyle {
internal fun parseCssStyleMapToParagraphStyle(
cssStyleMap: Map<String, String>,
attributes: Map<String,String>
): ParagraphStyle {
val direction = cssStyleMap["direction"] ?: attributes["dir"]
return ParagraphStyle(
textAlign = cssStyleMap["text-align"]?.let { parseCssTextAlign(it) } ?: TextAlign.Unspecified,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ internal object RichTextStateHtmlParser : RichTextStateParser<String> {
val paragraphType = encodeHtmlElementToRichParagraphType(lastOpenedTag)
currentRichParagraph.type = paragraphType

val cssParagraphStyle = CssEncoder.parseCssStyleMapToParagraphStyle(cssStyleMap,attributes)
val cssParagraphStyle = CssEncoder.parseCssStyleMapToParagraphStyle(cssStyleMap, attributes)
currentRichParagraph.paragraphStyle = currentRichParagraph.paragraphStyle.merge(cssParagraphStyle)
}

Expand All @@ -120,7 +120,7 @@ internal object RichTextStateHtmlParser : RichTextStateParser<String> {
if (name == "li" && lastOpenedTag != null) {
paragraphType = encodeHtmlElementToRichParagraphType(lastOpenedTag)
}
val cssParagraphStyle = CssEncoder.parseCssStyleMapToParagraphStyle(cssStyleMap,attributes)
val cssParagraphStyle = CssEncoder.parseCssStyleMapToParagraphStyle(cssStyleMap, attributes)

newRichParagraph.paragraphStyle = newRichParagraph.paragraphStyle.merge(cssParagraphStyle)
newRichParagraph.type = paragraphType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}

0 comments on commit ecdb801

Please sign in to comment.