Skip to content

Commit

Permalink
Fix content category of <audio> and <video> (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
xemlock authored Jun 7, 2018
1 parent 6f44fa7 commit 99f3df7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion library/HTMLPurifier/HTML5Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class HTMLPurifier_HTML5Config extends HTMLPurifier_Config
{
const REVISION = 2018060601;
const REVISION = 2018060701;

/**
* @param string|array|HTMLPurifier_Config $config
Expand Down
6 changes: 4 additions & 2 deletions library/HTMLPurifier/HTML5Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,23 @@ public static function setup(HTMLPurifier_HTMLDefinition $def)
$mediaContent = new HTMLPurifier_ChildDef_Media();

// https://html.spec.whatwg.org/dev/media.html#the-video-element
$def->addElement('video', 'Block', $mediaContent, 'Common', array(
$def->addElement('video', 'Flow', $mediaContent, 'Common', array(
'controls' => 'Bool',
'height' => 'Length',
'poster' => 'URI',
'preload' => 'Enum#auto,metadata,none',
'src' => 'URI',
'width' => 'Length',
));
$def->getAnonymousModule()->addElementToContentSet('video', 'Inline');

// https://html.spec.whatwg.org/dev/media.html#the-audio-element
$def->addElement('audio', 'Block', $mediaContent, 'Common', array(
$def->addElement('audio', 'Flow', $mediaContent, '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(
Expand Down
10 changes: 10 additions & 0 deletions tests/HTMLPurifier/HTML5DefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,15 @@ public function audioInput()
array('<audio src="audio.ogg">Your browser does not support audio</audio>'),
array('<audio src="audio.ogg"><p>Your browser does not support audio</p></audio>'),
array('<audio src="audio.ogg"><track kind="subtitles" src="subtitles.vtt"></audio>'),
array(
// <audio> is a phrasing content element
'<strong><audio controls><source type="audio/mp3" src="audio.mp3"></audio></strong>',
),
);
}

/**
* @param string $input
* @dataProvider audioInput
*/
public function testAudio($input)
Expand All @@ -150,10 +155,15 @@ public function videoInput()
array('<video><source src="video.mp4" type="video/mp4"></video>'),
array('<video><track kind="subtitles" src="subtitles.vtt"></video>'),
array('<video><source src="video.mp4" type="video/mp4"><track kind="subtitles" src="subtitles.vtt"></video>'),
array(
// <video> is a phrasing content element
'<em><video><source src="video.mp4" type="video/mp4"></video></em>',
),
);
}

/**
* @param string $input
* @dataProvider videoInput
*/
public function testVideo($input)
Expand Down

0 comments on commit 99f3df7

Please sign in to comment.