Skip to content

Commit

Permalink
Convert width attribute of col tag to equivalent CSS rule
Browse files Browse the repository at this point in the history
  • Loading branch information
amedina committed Apr 7, 2018
1 parent 5ba9f5b commit 6c095f4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions includes/sanitizers/class-amp-style-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ public function sanitize() {
$elements[] = $element;
}

// If 'width' attribute is present for 'col' tag, convert to proper CSS rule.
foreach ( $this->dom->getElementsByTagName( 'col' ) as $col ) {
$width_attr = $col->getAttribute( 'width' );
if ( ! empty( $width_attr ) ) {
$col->setAttribute( 'style', $width_attr . 'px' );
$col->removeAttribute( 'width' );
}
}

/**
* Element.
*
Expand Down
6 changes: 6 additions & 0 deletions tests/test-amp-style-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ public function get_body_style_attribute_data() {
'div > span { font-weight:bold; font-style: italic; }',
),
),

'col_with_width_attribute' => array(
'<table><colgroup><col width="253"/></colgroup></table>',
'<table><colgroup><col></colgroup></table>',
array(),
),
);
}

Expand Down

0 comments on commit 6c095f4

Please sign in to comment.