This is an automated email from the ASF dual-hosted git repository.

sdedic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new dbf1b142d8 Fix P + BR tag handling, LI is replaced by "* "
     new 1eb1c58ab6 Merge pull request #6375 from sdedic/lsp/fix-html-stripping
dbf1b142d8 is described below

commit dbf1b142d868465d287982c71a733df6f47c0247
Author: Svata Dedic <svatopluk.de...@oracle.com>
AuthorDate: Thu Aug 24 12:07:41 2023 +0200

    Fix P + BR tag handling, LI is replaced by "* "
---
 .../netbeans/modules/java/lsp/server/Utils.java    | 21 +++++++++++++++++++--
 .../modules/java/lsp/server/UtilsTest.java         | 22 ++++++++++++++++++++++
 2 files changed, 41 insertions(+), 2 deletions(-)

diff --git 
a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/Utils.java 
b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/Utils.java
index a4f04ce662..d913aab26e 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/Utils.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/Utils.java
@@ -414,21 +414,29 @@ public class Utils {
 
         int tagStart = -1;
         StringBuilder sb = new StringBuilder();
+        String additional = null;
         for (int i = 0; i < s.length(); i++) {
             char ch = s.charAt(i);
             T: if (inTag) {
                 boolean alpha = Character.isAlphabetic(ch);
                 if (tagStart > 0 && !alpha) {
                     String t = s.substring(tagStart, 
i).toLowerCase(Locale.ENGLISH);
+                    // prevent entering tagstart state again
+                    tagStart = -2;
+                    if (ch == '>') { // NOI18N
+                        inTag = false;
+                    }
                     switch (t) {
                         case "br": case "p": case "hr": // NOI1N
                             ch ='\n'; // NOI18N
                             // continues to process 'ch' as if it came from 
the string, but `inTag` remains
                             // the same.
                             break T;
+                        case "li":
+                            ch = '\n';
+                            additional = "* ";
+                            break T;
                     }
-                    // prevent entering tagstart state again
-                    tagStart = -2;
                 }
                 if (ch == '>') { // NOI18N
                     inTag = false;
@@ -441,6 +449,11 @@ public class Utils {
                     tagStart = -1;
                     inTag = true;
                     continue;
+                } else if (ch == '&') {
+                    if ("&nbsp;".contentEquals(s.subSequence(i, 
Math.min(s.length(), i + 6)))) {
+                        i += 5;
+                        ch = ' ';  // NOI18N
+                    }
                 }
             }
             if (collapseWhitespaces) {
@@ -458,6 +471,10 @@ public class Utils {
                 }
             }
             sb.append(ch);
+            if (additional != null) {
+                sb.append(additional);
+                additional = null;
+            }
         }
         return collapseWhitespaces ? sb.toString().trim() : sb.toString();
     }
diff --git 
a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/UtilsTest.java
 
b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/UtilsTest.java
index 24e997da75..f0ebdae200 100644
--- 
a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/UtilsTest.java
+++ 
b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/UtilsTest.java
@@ -82,4 +82,26 @@ public class UtilsTest {
         String result = Utils.html2plain(s, true);
         assertEquals(expResult, result);
     }
+    
+    /**
+     * LI is replaced by "* ".
+     */
+    @Test
+    public void testReplaceLiByAsterisk() {
+        String s = "<ul><li>First option<li>Next option</ul>";
+        String expResult = "* First option * Next option";
+        String result = Utils.html2plain(s, true);
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * "P" properly appends following text, it used to strip until the next 
tag.
+     */
+    @Test
+    public void testDontStripContentAfterTags() {
+        String s = "<html>The Java version: 19, that is selected for the 
project is not supported <p>Possible solutions:<ul>List content </ul>Epilog";
+        String expResult = "The Java version: 19, that is selected for the 
project is not supported Possible solutions:List content Epilog";
+        String result = Utils.html2plain(s, true);
+        assertEquals(expResult, result);
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to