【问题标题】:HTMLPurifier - add name attribute to anchor tagHTMLPurifier - 将名称属性添加到锚标记
【发布时间】:2015-05-03 23:46:41
【问题描述】:

HTMLPurifier 从anchor 标记中去除name 属性 过去使用documentation,我已经成功创建了一个新元素“include”。

但我无法获取代码来为anchor 标签添加name 属性。我的偏好不是限制 name 值。任何帮助将不胜感激。

这是代码:

$config = HTMLPurifier_Config::createDefault();
// custom tag for included files
$config->set('HTML.DefinitionID', 'include');
$config->set('HTML.DefinitionRev', 16);
if ($def = $config->maybeGetRawHTMLDefinition()) {
    // this works for adding the include element
    $def->addElement('include', 'Block', 'Empty', 'Common', array('file*' => 'URI', 'height' => 'Text', 'width' => 'Text'));

  // This doesn't work - among the many things, I've tried...
  // 1) trying to get at least name ="target" to work
  // $def->addAttribute('a', 'name', 'Enum#target');
  // 2) trying to get any text to work
  // $def->addAttribute('a', 'name', 'text');
  // $def->addAttribute('a', 'name', new HTMLPurifier_AttrDef_Text());
}

$purifier = new HTMLPurifier($config);

【问题讨论】:

    标签: php htmlpurifier


    【解决方案1】:

    我认为您必须在 Name.php 中将 name 属性设置为 true,请检查

    http://htmlpurifier.org/live/configdoc/plain.html#HTML.Attr.Name.UseCDATA

    【讨论】:

      【解决方案2】:

      看起来有两个选项。一种是使用HTML.Allowed 定义所有元素和标签。更简单的是设置Attr.EnableID,它允许idname 属性。设置Attr.IDPrefix 将有助于防止名称冲突。这有效:

      $config = HTMLPurifier_Config::createDefault();
      // allow name and id attributes
      $config->set('Attr.EnableID', true);
      // prefix all id and names with user_
      $config->set('Attr.IDPrefix', 'user_');
      
      // custom tag 
      $config->set('HTML.DefinitionID', 'include');
      $config->set('HTML.DefinitionRev', 2);
      if ($def = $config->maybeGetRawHTMLDefinition()) {
          $def->addElement('include', 'Block', 'Empty', 'Common', array('file*' => 'URI', 'height' => 'Text', 'width' => 'Text'));
      }
      
      $purifier = new HTMLPurifier($config);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-11-13
        • 2012-07-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-25
        • 2020-01-15
        • 1970-01-01
        相关资源
        最近更新 更多