public static function FilterHtml::mergeAllowedTags in Markdown 8.2
Merges allowed HTML tags.
Parameters
array $normalizedTags: An existing normalized allowed HTML tags array.
array ...$tags: One or more arrays of allowed HTML tags to merge onto $normalizedTags.
Return value
array The merged $normalizedTags.
2 calls to FilterHtml::mergeAllowedTags()
- FilterHtml::getHTMLRestrictions in src/
Util/ FilterHtml.php - Returns HTML allowed by this filter's configuration.
- Parsedown::allowedHtmlTags in src/
Plugin/ Markdown/ Parsedown/ Parsedown.php - Retrieves the allowed HTML tags.
File
- src/
Util/ FilterHtml.php, line 68
Class
- FilterHtml
- Extends FilterHtml to allow more more permissive global attributes.
Namespace
Drupal\markdown\UtilCode
public static function mergeAllowedTags(array $normalizedTags, array $tags) {
$args = func_get_args();
$normalizedTags = array_shift($args);
foreach ($args as $tags) {
if (!is_array($tags) || !$tags) {
continue;
}
// Normalize the tags to merge.
$tags = static::normalizeTags($tags);
foreach ($tags as $tag => $attributes) {
// Add tag if it doesn't already exist.
if (!isset($normalizedTags[$tag])) {
$normalizedTags[$tag] = $attributes;
continue;
}
// Existing tag already allows all attributes, skip merge.
if (!empty($normalizedTags[$tag]['*'])) {
continue;
}
// New tag allows all attributes, replace existing tag.
if (!empty($attributes['*'])) {
$normalizedTags[$tag] = [
'*' => TRUE,
];
continue;
}
// Now merge in individual attributes from tag.
foreach ($attributes as $name => $value) {
// Add attribute if it doesn't already exist.
if (!isset($normalizedTags[$tag][$name])) {
$normalizedTags[$tag][$name] = $value;
continue;
}
// Existing tag attribute already allows all values, skip merge.
if ($normalizedTags[$tag][$name] === TRUE) {
continue;
}
// New tag attribute allows all values, replace existing attribute.
if ($value === TRUE) {
$normalizedTags[$tag][$name] = $value;
continue;
}
// Finally, if specific attribute values are specified, merge them.
if (is_array($value)) {
if (!is_array($normalizedTags[$tag][$name])) {
$normalizedTags[$tag][$name] = [];
}
$normalizedTags[$tag][$name] = array_replace($normalizedTags[$tag][$name], $value);
}
}
}
}
ksort($normalizedTags);
return $normalizedTags;
}