Merge pull request #2338 from Progi1984/className
HTML Reader : Set style name from the CSS class
This commit is contained in:
commit
02e3aa96b6
@ -162,6 +162,7 @@ class Html
|
|||||||
$attributeClass = $attributes->getNamedItem('class');
|
$attributeClass = $attributes->getNamedItem('class');
|
||||||
if ($attributeClass && self::$css) {
|
if ($attributeClass && self::$css) {
|
||||||
$styles = self::parseStyleDeclarations(self::$css->getStyle('.' . $attributeClass->value), $styles);
|
$styles = self::parseStyleDeclarations(self::$css->getStyle('.' . $attributeClass->value), $styles);
|
||||||
|
$styles['className'] = $attributeClass->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
$attributeStyle = $attributes->getNamedItem('style');
|
$attributeStyle = $attributes->getNamedItem('style');
|
||||||
@ -411,6 +412,11 @@ class Html
|
|||||||
|
|
||||||
$newElement = $element->addTable($elementStyles);
|
$newElement = $element->addTable($elementStyles);
|
||||||
|
|
||||||
|
// Add style name from CSS Class
|
||||||
|
if (isset($elementStyles['className'])) {
|
||||||
|
$newElement->getStyle()->setStyleName($elementStyles['className']);
|
||||||
|
}
|
||||||
|
|
||||||
$attributes = $node->attributes;
|
$attributes = $node->attributes;
|
||||||
if ($attributes->getNamedItem('border') !== null) {
|
if ($attributes->getNamedItem('border') !== null) {
|
||||||
$border = (int) $attributes->getNamedItem('border')->value;
|
$border = (int) $attributes->getNamedItem('border')->value;
|
||||||
|
|||||||
@ -19,6 +19,7 @@ namespace PhpOffice\PhpWordTests\Shared;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use PhpOffice\PhpWord\Element\Section;
|
use PhpOffice\PhpWord\Element\Section;
|
||||||
|
use PhpOffice\PhpWord\Element\Table;
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpOffice\PhpWord\Shared\Html;
|
use PhpOffice\PhpWord\Shared\Html;
|
||||||
use PhpOffice\PhpWord\SimpleType\Jc;
|
use PhpOffice\PhpWord\SimpleType\Jc;
|
||||||
@ -134,6 +135,17 @@ class HtmlTest extends AbstractWebServerEmbeddedTest
|
|||||||
self::assertEquals('22.5', $doc->getElementAttribute('/w:document/w:body/w:p[2]/w:r/w:rPr/w:sz', 'w:val'));
|
self::assertEquals('22.5', $doc->getElementAttribute('/w:document/w:body/w:p[2]/w:r/w:rPr/w:sz', 'w:val'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testParseStyleTableClassName(): void
|
||||||
|
{
|
||||||
|
$html = '<style type="text/css">.pStyle { font-size:15px; }</style><table class="pStyle"><tr><td></td></tr></table>';
|
||||||
|
$phpWord = new PhpWord();
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
Html::addHtml($section, $html);
|
||||||
|
|
||||||
|
self::assertInstanceOf(Table::class, $section->getElement(0));
|
||||||
|
self::assertEquals('pStyle', $section->getElement(0)->getStyle()->getStyleName());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test underline.
|
* Test underline.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user