File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed
platforms/android/library/src
main/java/io/element/android/wysiwyg/utils
test/kotlin/io/element/android/wysiwyg/utils Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -388,7 +388,7 @@ internal class HtmlToSpansParser(
388388 } else if ((stripLeading && ! reachedNonWhite) || lastWasWhite) {
389389 i + = Character .charCount(c)
390390 continue
391- } else if (c == ' \n ' .code && i == text.length - 1 ) {
391+ } else if (c == ' \n ' .code && ( i == text.length - 1 || ! reachedNonWhite) ) {
392392 // Do nothing, this is probably just an HTML formatting line break
393393 } else {
394394 result.append(' ' )
Original file line number Diff line number Diff line change 99package io.element.android.wysiwyg.utils
1010
1111import android.text.Spanned
12- import io.element.android.wysiwyg.display.TextDisplay
1312import io.element.android.wysiwyg.display.MentionDisplayHandler
13+ import io.element.android.wysiwyg.display.TextDisplay
1414import io.element.android.wysiwyg.test.fakes.createFakeStyleConfig
1515import io.element.android.wysiwyg.test.utils.dumpSpans
1616import io.element.android.wysiwyg.view.spans.OrderedListSpan
@@ -270,6 +270,31 @@ class HtmlToSpansParserTest {
270270 )
271271 }
272272
273+ @Test
274+ fun testLeadingLineBreakCharsInHtmlTextAreIgnored () {
275+ val html = " <p>First Line</p>\n <p>Line after Empty Line<br />\n Third Line</p>\n "
276+ val spanned = convertHtml(
277+ html = html,
278+ isEditor = false ,
279+ )
280+ assertThat(
281+ spanned.toString(), equalTo(" First Line\n\n Line after Empty Line\n Third Line" )
282+ )
283+ }
284+
285+ @Test
286+ fun testLineBreakCharsInMiddleOrEndOfHtmlTextAreConvertedToWhitespace () {
287+ val html = " <p>First Line\n </p><p>Line after Empty Line<br />Third\n\n\n\n With more</p>"
288+ val spanned = convertHtml(
289+ html = html,
290+ isEditor = false ,
291+ )
292+ assertThat(
293+ spanned.toString(),
294+ equalTo(" First Line\n\n Line after Empty Line\n Third With more" )
295+ )
296+ }
297+
273298 private fun convertHtml (
274299 html : String ,
275300 isEditor : Boolean = true,
You can’t perform that action at this time.
0 commit comments