You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2017/06/01 09:05:00 UTC

[2/6] james-project git commit: JAMES-2018 Adding image alt support

JAMES-2018 Adding image alt support


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/72039450
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/72039450
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/72039450

Branch: refs/heads/master
Commit: 720394508448799ba6db5550e96f0e777363582d
Parents: b4c5215
Author: benwa <bt...@linagora.com>
Authored: Tue May 30 17:04:38 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Thu Jun 1 16:03:20 2017 +0700

----------------------------------------------------------------------
 .../org/apache/james/jmap/utils/JsoupHtmlTextExtractor.java   | 5 +++++
 .../apache/james/jmap/utils/JsoupHtmlTextExtractorTest.java   | 7 +++++++
 2 files changed, 12 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/72039450/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/JsoupHtmlTextExtractor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/JsoupHtmlTextExtractor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/JsoupHtmlTextExtractor.java
index ffc9a94..c153ae5 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/JsoupHtmlTextExtractor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/JsoupHtmlTextExtractor.java
@@ -38,6 +38,8 @@ public class JsoupHtmlTextExtractor implements HtmlTextExtractor {
     public static final String OL_TAG = "ol";
     public static final String LI_TAG = "li";
     public static final String P_TAG = "p";
+    public static final String IMG_TAG = "img";
+    public static final String ALT_TAG = "alt";
 
     @Override
     public String toPlainText(String html) {
@@ -77,6 +79,9 @@ public class JsoupHtmlTextExtractor implements HtmlTextExtractor {
             if (element.tagName().equals(P_TAG)) {
                 return "\n\n";
             }
+            if (element.tagName().equals(IMG_TAG)) {
+                return "[" + element.attributes().get(ALT_TAG) + "]";
+            }
         }
         return "";
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/72039450/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/JsoupHtmlTextExtractorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/JsoupHtmlTextExtractorTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/JsoupHtmlTextExtractorTest.java
index 97a161f..75ba62a 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/JsoupHtmlTextExtractorTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/JsoupHtmlTextExtractorTest.java
@@ -148,6 +148,13 @@ public class JsoupHtmlTextExtractorTest {
     }
 
     @Test
+    public void imgShouldBeWellHandled() {
+        String html = "<img src=\"whitePoney.png\" alt=\"My wonderfull white poney picture\"/>";
+        String expectedPlainText = "[My wonderfull white poney picture]";
+        assertThat(textExtractor.toPlainText(html)).isEqualTo(expectedPlainText);
+    }
+
+    @Test
     public void nonClosedHtmlShouldBeTranslated() {
         String html = "This is an <b>HTML text !";
         String expectedPlainText = "This is an HTML text !";


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org