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

public static 
bool
nameIsPattern(string $name)

Check if the name given for an element or attribute rule is a pattern.

public static 
string
patternToRegex(string $pattern)

Given a raw pattern, create a regex that does the match.

public static 
string
regexToPattern(string $regex)

Take a regex and convert it to a raw pattern compatible with arrays passed into HTMLEditorConfig::setElementRulesFromArray().

public
__construct()

No description

public
getGlobalRule()

Get the global rule that applies to all elements in this rule set.

public
array
getElementRules()

Get all element rules

public
array
getElementSubstitutionRules()

Get all element substitution rules.

public
addElementRule(HTMLEditorElementRule $rule)

Add an element rule to this ruleset.

public
addElementSubstitutionRule(string $from, string $to)

Add a rule for substituting one element with another.

public
removeElementRule(string $ruleName)

Remove an element rule from this ruleset.

public
HTMLEditorElementRule|null
getRuleForElement(string $tag)

Given an element name, get the element rule which applies if there is one.

public
bool
isElementAllowed(DOMElement $element)

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.

Parameters

string $name

Return Value

bool

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).

Parameters

string $pattern

Return Value

string

static string regexToPattern(string $regex)

Take a regex and convert it to a raw pattern compatible with arrays passed into HTMLEditorConfig::setElementRulesFromArray().

Parameters

string $regex

Return Value

string

__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.

Return Value

HTMLEditorElementRule

array getElementRules()

Get all element rules

Return Value

array

array getElementSubstitutionRules()

Get all element substitution rules.

Return Value

array

HTMLEditorRuleSet addElementRule(HTMLEditorElementRule $rule)

Add an element rule to this ruleset.

Parameters

HTMLEditorElementRule $rule

Return Value

HTMLEditorRuleSet

HTMLEditorRuleSet addElementSubstitutionRule(string $from, string $to)

Add a rule for substituting one element with another.

Parameters

string $from
string $to

Return Value

HTMLEditorRuleSet

HTMLEditorRuleSet removeElementRule(string $ruleName)

Remove an element rule from this ruleset.

Parameters

string $ruleName

Return Value

HTMLEditorRuleSet

HTMLEditorElementRule|null getRuleForElement(string $tag)

Given an element name, get the element rule which applies if there is one.

Parameters

string $tag

Return Value

HTMLEditorElementRule|null

bool isElementAllowed(DOMElement $element)

Check whether the given DOM element is allowed according to this rule.

Parameters

DOMElement $element

Return Value

bool