Commit 53766025 authored by webchick's avatar webchick

Issue #2656278 by miteshmap, walangitan, empesan, ejb503, manmohandream,...

Issue #2656278 by miteshmap, walangitan, empesan, ejb503, manmohandream, vaidehi bapat, gadaniels72, luca_cracco, swentel, malaimo29001, nileema.jadhav, sidharthap: Convert "Limit allowed HTML tags" input field to a textarea
parent 6008776f
......@@ -98,6 +98,9 @@
that.$allowedHTMLFormItem.on('change.updateUserTags', function () {
that.userTags = _.difference(that._parseSetting(this.value), that.autoTags);
});
}).on('keyup', function (e) {
if (e.keyCode != 13) return;
$(this).val($(this).val().replace(/\n/g, ""));
});
},
......@@ -238,36 +241,38 @@
var allowedTags = setting.match(/(<[^>]+>)/g);
var sandbox = document.createElement('div');
var rules = {};
for (var t = 0; t < allowedTags.length; t++) {
// Let the browser do the parsing work for us.
sandbox.innerHTML = allowedTags[t];
node = sandbox.firstChild;
tag = node.tagName.toLowerCase();
if (allowedTags) {
for (var t = 0; t < allowedTags.length; t++) {
// Let the browser do the parsing work for us.
sandbox.innerHTML = allowedTags[t];
node = sandbox.firstChild;
tag = (node !== null) ? node.tagName.toLowerCase() : null;
// Build the Drupal.FilterHtmlRule object.
rule = new Drupal.FilterHTMLRule();
// We create one rule per allowed tag, so always one tag.
rule.restrictedTags.tags = [tag];
// Add the attribute restrictions.
attributes = node.attributes;
for (var i = 0; i < attributes.length; i++) {
attribute = attributes.item(i);
var attributeName = attribute.nodeName;
// @todo Drupal.FilterHtmlRule does not allow for generic attribute
// value restrictions, only for the "class" and "style" attribute's
// values. The filter_html filter always disallows the "style"
// attribute, so we only need to support "class" attribute value
// restrictions. Fix once https://www.drupal.org/node/2567801 lands.
if (attributeName === 'class') {
var attributeValue = attribute.textContent;
rule.restrictedTags.allowed.classes = attributeValue.split(' ');
}
else {
rule.restrictedTags.allowed.attributes.push(attributeName);
// Build the Drupal.FilterHtmlRule object.
rule = new Drupal.FilterHTMLRule();
// We create one rule per allowed tag, so always one tag.
rule.restrictedTags.tags = [tag];
// Add the attribute restrictions.
attributes = (node !== null) ? node.attributes : '';
for (var i = 0; i < attributes.length; i++) {
attribute = attributes.item(i);
var attributeName = attribute.nodeName;
// @todo Drupal.FilterHtmlRule does not allow for generic attribute
// value restrictions, only for the "class" and "style" attribute's
// values. The filter_html filter always disallows the "style"
// attribute, so we only need to support "class" attribute value
// restrictions. Fix once https://www.drupal.org/node/2567801 lands.
if (attributeName === 'class') {
var attributeValue = attribute.textContent;
rule.restrictedTags.allowed.classes = attributeValue.split(' ');
}
else {
rule.restrictedTags.allowed.attributes.push(attributeName);
}
}
}
rules[tag] = rule;
rules[tag] = rule;
}
}
return rules;
},
......
......@@ -46,12 +46,10 @@ class FilterHtml extends FilterBase {
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$form['allowed_html'] = array(
'#type' => 'textfield',
'#type' => 'textarea',
'#title' => $this->t('Allowed HTML tags'),
'#default_value' => $this->settings['allowed_html'],
'#maxlength' => 2048,
'#description' => $this->t('A list of HTML tags that can be used. By default only the <em>lang</em> and <em>dir</em> attributes are allowed for all HTML tags. Each HTML tag may have attributes which are treated as allowed attribute names for that HTML tag. Each attribute may allow all values, or only allow specific values. Attribute names or values may be written as a prefix and wildcard like <em>jump-*</em>. JavaScript event attributes, JavaScript URLs, and CSS are always stripped.'),
'#size' => 250,
'#attached' => array(
'library' => array(
'filter/drupal.filter.filter_html.admin',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment