Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Commit

Permalink
fix(html-purifier): adds support for <audio> to htmlpurifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Campaña committed Aug 3, 2018
1 parent 0357caa commit 0261b70
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions libs/html5purifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ function load_html5purifier() {
$config->set('URI.SafeIframeRegexp', '/.+/');

// Rule: <center> not allowed.
$config->set('HTML', 'ForbiddenElements', array('center', 'font'));
$config->set('HTML', 'ForbiddenElements', array('font', 'center', 'br'));

// Rule: remove empty elements.
$config->set('AutoFormat', 'RemoveEmpty', true);
$config->set('AutoFormat', 'RemoveEmpty.RemoveNbsp', true);
$config->set('AutoFormat', 'AutoParagraph', true);

// Set some HTML5 properties
$config->set('HTML.DefinitionID', 'html5-definitions'); // unqiue id
$config->set('HTML.DefinitionID', 'html5-definitions'); // unique id
$config->set('HTML.DefinitionRev', 1);

if ($def = $config->maybeGetRawHTMLDefinition()) {
Expand All @@ -52,19 +52,38 @@ function load_html5purifier() {
// http://developers.whatwg.org/grouping-content.html
$def->addElement('figure', 'Block', 'Optional: (figcaption, Flow) | (Flow, figcaption) | Flow', 'Common');
$def->addElement('figcaption', 'Inline', 'Flow', 'Common');
// http://developers.whatwg.org/the-video-element.html#the-video-element
$def->addElement('video', 'Block', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', array(
'src' => 'URI',
'type' => 'Text',
'width' => 'Length',
'height' => 'Length',
'poster' => 'URI',
'preload' => 'Enum#auto,metadata,none',
'controls' => 'Bool',
// https://html.spec.whatwg.org/dev/media.html#the-video-element
$def->addElement('video', 'Block', 'Flow', 'Common', array(
'controls' => 'Bool',
'height' => 'Length',
'poster' => 'URI',
'preload' => 'Enum#auto,metadata,none',
'src' => 'URI',
'width' => 'Length',
));
$def->addElement('source', 'Block', 'Empty', 'Common', array(
'src' => 'URI',
'type' => 'Text',
$def->getAnonymousModule()->addElementToContentSet('video', 'Inline');
// https://html.spec.whatwg.org/dev/media.html#the-audio-element
$def->addElement('audio', 'Block', 'Flow', 'Common', array(
'controls' => 'Bool',
'preload' => 'Enum#auto,metadata,none',
'src' => 'URI',
));
$def->getAnonymousModule()->addElementToContentSet('audio', 'Inline');
// https://html.spec.whatwg.org/dev/embedded-content.html#the-source-element
$def->addElement('source', false, 'Empty', 'Common', array(
'media' => 'Text',
'sizes' => 'Text',
'src' => 'URI',
'srcset' => 'Text',
'type' => 'Text',
));
// https://html.spec.whatwg.org/dev/media.html#the-track-element
$def->addElement('track', false, 'Empty', 'Common', array(
'kind' => 'Enum#captions,chapters,descriptions,metadata,subtitles',
'src' => 'URI',
'srclang' => 'Text',
'label' => 'Text',
'default' => 'Bool',
));
// http://developers.whatwg.org/text-level-semantics.html
$def->addElement('s', 'Inline', 'Inline', 'Common');
Expand Down

0 comments on commit 0261b70

Please sign in to comment.