I am trying to resolve some data-attribute with htmlPurifier for all my span , but no way ...
I have this line:
<p> <span data-time-start="1" data-time-end="5" id="5"> <word class="word">My</word> <word class="word">Name</word> </span> <span data-time-start="6" data-time-end="15" id="88"> <word class="word">Is</word> <word class="word">Zooboo</word> </span> <p>
My htmlpurifier configuration:
$this->HTMLpurifierConfigInverseTransform = \HTMLPurifier_Config::createDefault(); $this->HTMLpurifierConfigInverseTransform->set('HTML.Allowed', 'span,u,strong,em'); $this->HTMLpurifierConfigInverseTransform->set('HTML.ForbiddenElements', 'word,p'); $this->HTMLpurifierConfigInverseTransform->set('CSS.AllowedProperties', 'font-weight, font-style, text-decoration'); $this->HTMLpurifierConfigInverseTransform->set('AutoFormat.RemoveEmpty', true);
I clear my $value as follows:
$purifier = new \HTMLPurifier($this->HTMLpurifierConfigInverseTransform); var_dump($purifier->purify($value));die;
And get the following:
<span>My Name</span><span>Is Zoobo</span>
But how to save my id , data-time-start , data-time-end data attributes in my span ?
I need to have this:
<span data-time-start="1" data-time-end="5" id="5">My Name</span data-time-start="6" data-time-end="15" id="88"><span>Is Zoobo</span>
I tried to test this configuration:
$this->HTMLpurifierConfigInverseTransform->set('HTML.Allowed', 'span[data-time-start],u,strong,em');
but the error message is:
User warning: attribute 'data-time-start' in the element 'span' not (for information on this, see the support forums)
Thanks for the help!
EDIT 1
I tried to resolve the id for firdt with this line of code:
$this->HTMLpurifierConfigInverseTransform->set('Attr.EnableID', true);
This does not work for me ...
EDIT 2
For data-* attributes, I add this line, but nothing happened ...
$def = $this->HTMLpurifierConfigInverseTransform->getHTMLDefinition(true); $def->addAttribute('sub', 'data-time-start', 'CDATA'); $def->addAttribute('sub', 'data-time-end', 'CDATA');