Whitelist
Whitelist.swift:60class Whitelist
class Whitelist
import SwiftSoup
static func basic() throws -> Whitelist
static func basicWithImages() throws -> Whitelist
This whitelist allows the same text tags as {@link #basic}, and also allows img
tags, with appropriate attributes, with src
pointing to http
or https
.
static func none() -> Whitelist
This whitelist allows only text nodes: all HTML will be stripped.
static func relaxed() throws -> Whitelist
This whitelist allows a full range of text and structural body HTML: a, b, blockquote, br, caption, cite, code, col, colgroup, dd, div, dl, dt, em, h1, h2, h3, h4, h5, h6, i, img, li, ol, p, pre, q, small, span, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, u, ul
static func simpleText() throws -> Whitelist
This whitelist allows only simple text formatting: b, em, i, strong, u
. All other HTML (tags and attributes) will be removed.
@discardableResult func addAttributes(_ tag: String, _ keys: String...) throws -> Whitelist
Add a list of allowed attributes to a tag. (If an attribute is not allowed on an element, it will be removed.)
@discardableResult func addEnforcedAttribute(_ tag: String, _ key: String, _ value: String) throws -> Whitelist
Add an enforced attribute to a tag. An enforced attribute will always be added to the element. If the element already has the attribute set, it will be overridden.
@discardableResult func addProtocols(_ tag: String, _ key: String, _ protocols: String...) throws -> Whitelist
Add allowed URL protocols for an element’s URL attribute. This restricts the possible values of the attribute to URLs with the defined protocol.
@discardableResult func addTags(_ tags: String...) throws -> Whitelist
Add a list of allowed elements to a whitelist. (If a tag is not allowed, it will be removed from the HTML.)
func getEnforcedAttributes(_ tagName: String) throws -> Attributes
func isSafeAttribute(_ tagName: String, _ el: Element, _ attr: Attribute) throws -> Bool
Test if the supplied attribute is allowed by this whitelist for this tag
func isSafeTag(_ tag: [UInt8]) -> Bool
Test if the supplied tag is allowed by this whitelist
@discardableResult func preserveRelativeLinks(_ preserve: Bool) -> Whitelist
Configure this Whitelist to preserve relative links in an element’s URL attribute, or convert them to absolute links. By default, this is false: URLs will be made absolute (e.g. start with an allowed protocol, like e.g. {@code http://}.
@discardableResult func removeAttributes(_ tag: String, _ keys: String...) throws -> Whitelist
Remove a list of allowed attributes from a tag. (If an attribute is not allowed on an element, it will be removed.)
@discardableResult func removeEnforcedAttribute(_ tag: String, _ key: String) throws -> Whitelist
Remove a previously configured enforced attribute from a tag.
@discardableResult func removeProtocols(_ tag: String, _ key: String, _ protocols: String...) throws -> Whitelist
Remove allowed URL protocols for an element’s URL attribute.
@discardableResult func removeTags(_ tags: String...) throws -> Whitelist
Remove a list of allowed elements from a whitelist. (If a tag is not allowed, it will be removed from the HTML.)