HTMLEditorRuleSet
class HTMLEditorRuleSet (View source)
A set of rules to determine which elements and attributes are allowed for a given HTMLEditorConfig.
This ruleset will be used by HTMLEditorSanitiser for server-side sanitisation of HTML.
Methods
Check if the name given for an element or attribute rule is a pattern.
Given a raw pattern, create a regex that does the match.
Take a regex and convert it to a raw pattern compatible with arrays passed into HTMLEditorConfig::setElementRulesFromArray().
Get the global rule that applies to all elements in this rule set.
Add a rule for substituting one element with another.
Remove an element rule from this ruleset.
Given an element name, get the element rule which applies if there is one.
Check whether the given DOM element is allowed according to this rule.
Details
static bool
nameIsPattern(string $name)
Check if the name given for an element or attribute rule is a pattern.
If so, it should be passed through patternToRegex() before being passed into the rule's constructor.
static string
patternToRegex(string $pattern)
Given a raw pattern, create a regex that does the match.
Raw patterns can use the following special characters:
*
Matches between zero and unlimited characters (equivalent to.*
in regex).?
Matches between zero and one characters (equivalent to.?
in regex).+
Matches exactly one character (equivalent to.+
in regex).
static string
regexToPattern(string $regex)
Take a regex and convert it to a raw pattern compatible with arrays passed into HTMLEditorConfig::setElementRulesFromArray().
__construct()
No description
HTMLEditorElementRule
getGlobalRule()
Get the global rule that applies to all elements in this rule set.
The global rule will only contain attribute rules - e.g. getPadEmpty() will always return false.
array
getElementRules()
Get all element rules
array
getElementSubstitutionRules()
Get all element substitution rules.
HTMLEditorRuleSet
addElementRule(HTMLEditorElementRule $rule)
Add an element rule to this ruleset.
HTMLEditorRuleSet
addElementSubstitutionRule(string $from, string $to)
Add a rule for substituting one element with another.
HTMLEditorRuleSet
removeElementRule(string $ruleName)
Remove an element rule from this ruleset.
HTMLEditorElementRule|null
getRuleForElement(string $tag)
Given an element name, get the element rule which applies if there is one.
bool
isElementAllowed(DOMElement $element)
Check whether the given DOM element is allowed according to this rule.