Java Code Examples for org.jsoup.safety.Whitelist#addTags()
The following examples show how to use
org.jsoup.safety.Whitelist#addTags() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextFilterManage.java From bbs with GNU Affero General Public License v3.0 | 5 votes |
/** * 文本过滤标签,只保留<br>标签 * @param html * @return */ public String filterTag_br(String html) { if(StringUtils.isBlank(html)) return ""; Whitelist whitelist = Whitelist.none();//只保留文本,其他所有的html内容均被删除 whitelist.addTags("br"); return Jsoup.clean(html, whitelist); //return Jsoup.clean(html,"", whitelist,new OutputSettings().prettyPrint(false)); //prettyPrint(是否重新格式化) }
Example 2
Source File: Utilities.java From inception with Apache License 2.0 | 5 votes |
public static String cleanHighlight(String aHighlight) { Whitelist wl = new Whitelist(); wl.addTags("em"); Document dirty = Jsoup.parseBodyFragment(aHighlight, ""); Cleaner cleaner = new Cleaner(wl); Document clean = cleaner.clean(dirty); clean.select("em").tagName("mark"); return clean.body().html(); }
Example 3
Source File: HTMLSanitizer.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
public static String sanitize(String unsafeHtmlContent) { Whitelist whiteList = Whitelist.relaxed().preserveRelativeLinks(true); whiteList = whiteList.addTags("head", "html", "style", "body", "fieldsMap", "area"); whiteList = whiteList.addAttributes(":all", "name", "class", "style", "id", "src", "type", "cellpadding", "cellspacing", "alt", "title", "shape", "coords", "width", "height", "dir"); whiteList = whiteList.addProtocols("img", "src", "http", "https", "data", "cid"); return Jsoup.clean(unsafeHtmlContent, whiteList); }
Example 4
Source File: HtmlParser.java From scava with Eclipse Public License 2.0 | 5 votes |
private static Whitelist whitelist(String extraTagToRemoveWhitelist, String extraTagToAddWhiteList) { Whitelist newWhiteList = whitelist; if(extraTagToRemoveWhitelist!=null && !extraTagToRemoveWhitelist.isEmpty()) newWhiteList.removeTags(extraTagToRemoveWhitelist); if(extraTagToAddWhiteList!=null && !extraTagToAddWhiteList.isEmpty()) newWhiteList.addTags(extraTagToAddWhiteList); return newWhiteList; }
Example 5
Source File: HtmlParser.java From scava with Eclipse Public License 2.0 | 5 votes |
private static Whitelist whitelist(String[] extraTagsToRemoveWhitelist, String[] extraTagsToAddWhiteList) { Whitelist newWhiteList = whitelist; if(extraTagsToRemoveWhitelist!=null && extraTagsToRemoveWhitelist.length>0) newWhiteList.removeTags(extraTagsToRemoveWhitelist); if(extraTagsToAddWhiteList!=null && extraTagsToAddWhiteList.length>0) newWhiteList.addTags(extraTagsToAddWhiteList); return whitelist.removeTags(extraTagsToRemoveWhitelist); }
Example 6
Source File: FeedUtils.java From commafeed with Apache License 2.0 | 5 votes |
private static synchronized Whitelist buildWhiteList() { Whitelist whitelist = new Whitelist(); whitelist.addTags("a", "b", "blockquote", "br", "caption", "cite", "code", "col", "colgroup", "dd", "div", "dl", "dt", "em", "h1", "h2", "h3", "h4", "h5", "h6", "i", "iframe", "img", "li", "ol", "p", "pre", "q", "small", "strike", "strong", "sub", "sup", "table", "tbody", "td", "tfoot", "th", "thead", "tr", "u", "ul"); whitelist.addAttributes("div", "dir"); whitelist.addAttributes("pre", "dir"); whitelist.addAttributes("code", "dir"); whitelist.addAttributes("table", "dir"); whitelist.addAttributes("p", "dir"); whitelist.addAttributes("a", "href", "title"); whitelist.addAttributes("blockquote", "cite"); whitelist.addAttributes("col", "span", "width"); whitelist.addAttributes("colgroup", "span", "width"); whitelist.addAttributes("iframe", "src", "height", "width", "allowfullscreen", "frameborder", "style"); whitelist.addAttributes("img", "align", "alt", "height", "src", "title", "width", "style"); whitelist.addAttributes("ol", "start", "type"); whitelist.addAttributes("q", "cite"); whitelist.addAttributes("table", "border", "bordercolor", "summary", "width"); whitelist.addAttributes("td", "border", "bordercolor", "abbr", "axis", "colspan", "rowspan", "width"); whitelist.addAttributes("th", "border", "bordercolor", "abbr", "axis", "colspan", "rowspan", "scope", "width"); whitelist.addAttributes("ul", "type"); whitelist.addProtocols("a", "href", "ftp", "http", "https", "magnet", "mailto"); whitelist.addProtocols("blockquote", "cite", "http", "https"); whitelist.addProtocols("img", "src", "http", "https"); whitelist.addProtocols("q", "cite", "http", "https"); whitelist.addEnforcedAttribute("a", "target", "_blank"); whitelist.addEnforcedAttribute("a", "rel", "noreferrer"); return whitelist; }