jsoup line feed

前端 未结 2 621
闹比i
闹比i 2020-12-06 16:58

We\'re using Jsoup.clean(String, Whitelist) to process some input, and it appears that Jsoup is adding an extraneous line break just prior to acceptable tags. I\'ve seen a f

2条回答
  •  天命终不由人
    2020-12-06 17:51

    Addendum:

    I just downloaded Jsoup 1.7.1, in this version it's possible to use clean()-method with custom OutputSettings:

    String html = "This is a line with bold text within it.";
    
    OutputSettings settings = new OutputSettings();
    settings.prettyPrint(false);
    
    String clean = Jsoup.clean(html, "", Whitelist.relaxed(), settings);
    

    Or shorter:

    String clean = Jsoup.clean(html, "", Whitelist.relaxed(), new OutputSettings().prettyPrint(false));
    

    (In fact its the same solution like posted in the comments)

提交回复
热议问题