jsoup to strip only html tags not new line character?

后端 未结 2 1400
耶瑟儿~
耶瑟儿~ 2021-01-16 11:24

I have below content in Java where I want to strip only html tags but not new line characters

test1 test2 test 3

//lin
2条回答
  •  -上瘾入骨i
    2021-01-16 11:53

    You can also do this:

    public static String cleanNoMarkup(String input) {
        final Document.OutputSettings outputSettings = new Document.OutputSettings().prettyPrint(false);
        String output = Jsoup.clean(input, "", Whitelist.none(), outputSettings);
        return output;
    
    }
    

    The important things here are: 1. Whitelist.none() - so no markup is allowed 2..prettyPrint(false) - so linebreaks are not removed

提交回复
热议问题