我无法将自定义标签添加到HTML Purifier中

时间:2019-06-21 08:07:13

标签: php htmlpurifier

根据http://htmlpurifier.org/docs/enduser-customize.html,我尝试将自定义标记添加到htmlpurifier。但它仅适用于

之类的已知标签
   ansible.errors.AnsibleFileNotFound: Could not find or access 'tmp/satestfile'
    Searched in:
        /var/lib/awx/projects/simon/files/tmp/satestfile
        /var/lib/awx/projects/simon/tmp/satestfile
        /var/lib/awx/projects/simon/files/tmp/satestfile…

我尝试过HTML。可以这样:

    require_once __DIR__ . '/htmlpurifier-4.10.0/library/HTMLPurifier.auto.php';

    $config = HTMLPurifier_Config::createDefault();

    $config->set('HTML.DefinitionRev', 1);
    $config->set('Cache.DefinitionImpl', null);
    $def = $config->getHTMLDefinition(true);

    $form = $def->addElement(
        'form',
        'Block',
        'Flow',
        'Common',
        array(
            'action*' => 'URI',
            'method' => 'Enum#get|post',
            'name' => 'ID'
        )
    );
    $form->excludes = array('form' => true);

    $vroundrect = $def->addElement(
        'v:roundrect',
        'Block|Inline',
        'Optional: Flow|Inline',
        'Common',
        array(
            'xmlns:v' => 'CDATA',
            'xmlns:w' => 'CDATA'
        )
    );
    $vroundrect->excludes = array('v:roundrect' => true);

    $mytag = $def->addElement(
        'mytag',
        'Block|Inline',
        'Optional: Flow|Inline',
        'Common',
        array(
        )
    );
    $mytag->excludes = array('mytag' => true);

    $purifier = new HTMLPurifier($config);
    print $purifier->purify(file_get_contents(__DIR__ . '/tmpHTML2.txt'));

这不起作用。什么我不希望替换可用标签列表,我想将新标签添加到可用标签列表。

tmpHTML2.txt: 11111111
mytag内容
http://sdsd.com"></form&gt;

结果: 11111111 http://sdsd.com"></form&gt;

标签被忽略。标记的消毒程度超出了预期。

1 个答案:

答案 0 :(得分:0)

我已经在另一台计算机上尝试过此代码,并且可以正常工作。我认为这是缓存问题。看起来像指令$ config-> set('Cache.DefinitionImpl',null);不禁用缓存。我将尝试从库/ HTMLPurifier / DefinitionCache / Serializer中删除文件。无论解决了什么问题。