diff --git a/app/src/sharedTest/java/org/oppia/android/app/parser/HtmlParserTest.kt b/app/src/sharedTest/java/org/oppia/android/app/parser/HtmlParserTest.kt
index 1e1ca843c6a..9b3b36f2d6a 100644
--- a/app/src/sharedTest/java/org/oppia/android/app/parser/HtmlParserTest.kt
+++ b/app/src/sharedTest/java/org/oppia/android/app/parser/HtmlParserTest.kt
@@ -427,6 +427,57 @@ class HtmlParserTest {
assertThat(htmlResult.toString()).endsWith(" ")
}
+ @Test
+ fun testHtmlContentParsing_removesUnwantedNewlines() {
+ val htmlParser = htmlParserFactory.create(
+ resourceBucketName,
+ entityType = "",
+ entityId = "",
+ imageCenterAlign = true,
+ displayLocale = appLanguageLocaleHandler.getDisplayLocale()
+ )
+ val (_, htmlResult) = activityScenarioRule.scenario.runWithActivity {
+ val textView: TextView = it.findViewById(R.id.test_html_content_text_view)
+ val htmlResult = htmlParser.parseOppiaHtml(
+ "
- \n\tThe counting numbers (1, 2, 3, 4, 5 ….)\n\n
- \n\tHow to tell" +
+ " whether one counting number is bigger or smaller than another.\n\n
",
+ textView
+ )
+ textView.text = htmlResult
+ return@runWithActivity textView to htmlResult
+ }
+
+ assertThat(htmlResult.toString()).isEqualTo(
+ "The counting numbers (1, 2, 3, 4, 5 ….)\nHow to tell whether one counting " +
+ "number is bigger or smaller than another"
+ )
+ }
+
+ @Test
+ fun testHtmlContentParsing_withImageTag_trimsLeadingAndTrailingNewlines() {
+ val htmlParser = htmlParserFactory.create(
+ resourceBucketName,
+ entityType = "",
+ entityId = "",
+ imageCenterAlign = true,
+ displayLocale = appLanguageLocaleHandler.getDisplayLocale()
+ )
+ val htmlResult = activityScenarioRule.scenario.runWithActivity {
+ val textView: TextView = it.findViewById(R.id.test_html_content_text_view)
+ return@runWithActivity htmlParser.parseOppiaHtml(
+ "\n" +
+ "\n",
+ textView
+ )
+ }
+ val imageSpans = htmlResult.getSpansFromWholeString(ImageSpan::class)
+ assertThat(imageSpans).hasLength(1)
+ assertThat(imageSpans.first().source).isEqualTo("test.png")
+
+ assertThat(htmlResult.toString().startsWith("\n")).isFalse()
+ assertThat(htmlResult.toString().endsWith("\n")).isFalse()
+ }
+
@Test
fun testHtmlContent_changeDeviceToLtr_textViewDirectionIsSetToLtr() {
val htmlParser = htmlParserFactory.create(