Jsoup.clean - nie rozpoznaje \r\n

0

Cześć, mam problem z Jsoup.clean, mianowicie nie mam tekst w którym występuje \r - powrót karetki i \n - nowa linia w tekscie. Chciałbym to zachować ponieważ po zatwierdzeniu formularza, z tekstu usuwa mi te znaczniki

przykład :

 @Test
    public void testCleanHtmlText() throws Exception {

        String result = TextUtil.cleanHtmlText("dupa \r\n" +
                "");
        String excepted = "dupa \r\n" +
                "";
        Assert.assertEquals(excepted, result);

    }

logika :

public class TextUtil {

    public static String cleanHtmlText(String text) {
        String processedText = Jsoup.clean(text, whitelist());
        return processedText.replaceAll(" ", " ");
    }

    private static Whitelist whitelist() {
        return new Whitelist()
                
                .addTags("b", "i", "u",  "ul", "li", "ol", "p", "cite", "sub", "sup", "strike",  "strong", "small", "pre", "br", "\\t", "\\r", "\\n");
    }
}

Dlaczego to ucina mi \r\n ?

0

Wygląda na to że rozwiązałem problem :

 public static String cleanHtmlText(String text) {
        Document document = Jsoup.parse(text);
        document.outputSettings(new Document.OutputSettings().prettyPrint(false));//makes html() preserve linebreaks and spacing
        document.select("br").append("\\n");
        document.select("p").prepend("\\n\\n");
        String s = document.html().replaceAll("\\\\n", "\n");
        String processedText = Jsoup.clean(s, "", whitelist().none(), new Document.OutputSettings().prettyPrint(false));
        return processedText.replaceAll(" ", " ");
    }

    private static Whitelist whitelist() {
        return new Whitelist()

                .addTags("b", "i", "u",  "ul", "li", "ol", "p", "cite", "sub", "sup", "strike",  "strong", "small", "pre");

    }
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1