From a3bf389065be1bae18887289afe9554e60492970 Mon Sep 17 00:00:00 2001 From: cketti Date: Fri, 24 Apr 2020 00:30:35 +0200 Subject: [PATCH] Properly handle
tag when converting HTML to plain text --- .../fsck/k9/message/html/HtmlToPlainText.kt | 1 + .../k9/message/html/HtmlConverterTest.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/core/src/main/java/com/fsck/k9/message/html/HtmlToPlainText.kt b/app/core/src/main/java/com/fsck/k9/message/html/HtmlToPlainText.kt index dee5ed93f..901069430 100644 --- a/app/core/src/main/java/com/fsck/k9/message/html/HtmlToPlainText.kt +++ b/app/core/src/main/java/com/fsck/k9/message/html/HtmlToPlainText.kt @@ -41,6 +41,7 @@ private class FormattingVisitor : NodeVisitor { val name = node.nodeName() when { name == "li" -> append("\n") + name == "br" -> append("\n") node is Element && node.isBlock -> { if (node.hasText()) { addEmptyLine() diff --git a/app/core/src/test/java/com/fsck/k9/message/html/HtmlConverterTest.java b/app/core/src/test/java/com/fsck/k9/message/html/HtmlConverterTest.java index 7109f8908..3b8c1423d 100644 --- a/app/core/src/test/java/com/fsck/k9/message/html/HtmlConverterTest.java +++ b/app/core/src/test/java/com/fsck/k9/message/html/HtmlConverterTest.java @@ -249,4 +249,22 @@ public class HtmlConverterTest { String result = HtmlConverter.textToHtml(text); assertEquals("
hello
world
", result); } + + @Test + public void htmlToText_withLineBreaks() { + String input = "One
Two

Three"; + + String result = HtmlConverter.htmlToText(input); + + assertEquals("One\nTwo\n\nThree", result); + } + + @Test + public void htmlToText_withBlockElements() { + String input = "

One

Two
Three

Four
"; + + String result = HtmlConverter.htmlToText(input); + + assertEquals("One\n\nTwo\nThree\n\nFour", result); + } }