allowing data-* attributes with HTMLPurifier

后端 未结 3 1669
青春惊慌失措
青春惊慌失措 2021-02-07 21:33

Currently I am using this code with HTMLPurifier to allow data-* HTML tag attributes:

    $def = $config->getHTMLDefinition(true);
    $def->a         


        
3条回答
  •  情深已故
    2021-02-07 22:10

    It's not a full solution, but I was able to globally white-list individual data- attributes with the follow code, allowing them to be placed on any element without having to itemize each element type for each attribute.

    $def = $config->getHTMLDefinition(true);
    $def->info_global_attr['data-aaa-xxx'] = new HTMLPurifier_AttrDef_Text;
    $def->info_global_attr['data-bbb-yyy'] = new HTMLPurifier_AttrDef_Text;
    $def->info_global_attr['data-ccc-zzz'] = new HTMLPurifier_AttrDef_Text;
    

提交回复
热议问题