HTML Reader : Use `border` attribute for tables
This commit is contained in:
parent
a006aa8780
commit
a4cdcd6250
|
|
@ -372,17 +372,11 @@ class Html
|
|||
|
||||
$newElement = $element->addTable($elementStyles);
|
||||
|
||||
// $attributes = $node->attributes;
|
||||
// if ($attributes->getNamedItem('width') !== null) {
|
||||
// $newElement->setWidth($attributes->getNamedItem('width')->value);
|
||||
// }
|
||||
|
||||
// if ($attributes->getNamedItem('height') !== null) {
|
||||
// $newElement->setHeight($attributes->getNamedItem('height')->value);
|
||||
// }
|
||||
// if ($attributes->getNamedItem('width') !== null) {
|
||||
// $newElement=$element->addCell($width=$attributes->getNamedItem('width')->value);
|
||||
// }
|
||||
$attributes = $node->attributes;
|
||||
if ($attributes->getNamedItem('border') !== null) {
|
||||
$border = (int) $attributes->getNamedItem('border')->value;
|
||||
$newElement->getStyle()->setBorderSize(Converter::pixelToTwip($border));
|
||||
}
|
||||
|
||||
return $newElement;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -351,6 +351,35 @@ class HtmlTest extends AbstractWebServerEmbeddedTest
|
|||
$this->assertFalse($doc->elementExists('/w:document/w:body/w:tbl/w:tr[1]/w:tc[2]/w:p/w:pPr/w:pBdr'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test parsing table (attribute border)
|
||||
*/
|
||||
public function testParseTableAttributeBorder()
|
||||
{
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
$section = $phpWord->addSection();
|
||||
$html = '<table border="10">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Header</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr><td>Cell 1</td></tr>
|
||||
<tr><td>Cell 2</td></tr>
|
||||
</tbody>
|
||||
</table>';
|
||||
Html::addHtml($section, $html);
|
||||
|
||||
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
||||
$this->assertTrue($doc->elementExists('/w:document/w:body/w:tbl'));
|
||||
$this->assertTrue($doc->elementExists('/w:document/w:body/w:tbl/w:tblPr'));
|
||||
$this->assertTrue($doc->elementExists('/w:document/w:body/w:tbl/w:tblPr/w:tblBorders'));
|
||||
$this->assertTrue($doc->elementExists('/w:document/w:body/w:tbl/w:tblPr/w:tblBorders/w:top'));
|
||||
// 10 pixels = 150 twips
|
||||
$this->assertEquals(150, $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tblPr/w:tblBorders/w:top', 'w:sz'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests parsing of ul/li
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue