Skip to content

Commit

Permalink
Add HTML5 spec compliant <caption> definition
Browse files Browse the repository at this point in the history
  • Loading branch information
codebymikey committed Aug 5, 2022
1 parent 941bc75 commit 0170396
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion library/HTMLPurifier/HTML5Config.php
Expand Up @@ -2,7 +2,7 @@

class HTMLPurifier_HTML5Config extends HTMLPurifier_Config
{
const REVISION = 2021091901;
const REVISION = 2022080501;

/**
* @param string|array|HTMLPurifier_Config $config
Expand Down
4 changes: 3 additions & 1 deletion library/HTMLPurifier/HTMLModule/HTML5/Tables.php
Expand Up @@ -17,7 +17,9 @@ class HTMLPurifier_HTMLModule_HTML5_Tables extends HTMLPurifier_HTMLModule
*/
public function setup($config)
{
$this->addElement('caption', false, 'Inline', 'Common');
// https://html.spec.whatwg.org/multipage/tables.html#the-caption-element
$caption = $this->addElement('caption', false, 'Flow', 'Common');
$caption->excludes = $this->makeLookup('table');

$this->addElement('table', 'Block', new HTMLPurifier_ChildDef_HTML5_Table(), 'Common');

Expand Down
8 changes: 8 additions & 0 deletions tests/HTMLPurifier/HTMLModule/HTML5/TablesTest.php
Expand Up @@ -6,6 +6,14 @@ public function dataProvider()
{
return array(
array('<table></table>'),
array('<table><caption><h3>foo</h3><p>bar<p>baz</caption></table>', '<table><caption><h3>foo</h3><p>bar</p><p>baz</p></caption></table>'),
array('<table><caption><h3>foo</h3></caption></table>'),
array('<table><caption><p>foo<p>bar</caption></table>', '<table><caption><p>foo</p><p>bar</p></caption></table>'),
array('<table><caption>foo</caption></table>'),
array('<table><caption>foo</table>', '<table><caption>foo</caption></table>'),
array('<table><caption>foo </table>', '<table><caption>foo </caption></table>'),
array('<table><caption><div>foo<table></table>bar</div> baz</caption></table>', '<table><caption><div>foobar</div> baz</caption></table>'),
array('<table><tbody><tr><th>foo</th></tr></tbody><caption>foo</caption></table>', '<table><caption>foo</caption><tbody><tr><th>foo</th></tr></tbody></table>'),
array('<table><thead><tr><th>foo</th></tr></thead></table>'),
array('<table><tr><th>foo</th></tr></table>'),
array('<table><tbody><tr><th>foo</th></tr></tbody></table>'),
Expand Down

0 comments on commit 0170396

Please sign in to comment.