diff --git a/.gitignore b/.gitignore
index dd858ceac6..f5f6f7eb81 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,3 +21,4 @@ phpword.ini
/.project
/nbproject
/.php_cs.cache
+/.phpunit.result.cache
diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php
index 02534736b0..ad5aec1181 100644
--- a/src/PhpWord/Shared/Html.php
+++ b/src/PhpWord/Shared/Html.php
@@ -107,10 +107,6 @@ protected static function parseInlineStyle($node, $styles = [])
foreach ($attributes as $attribute) {
$val = $attribute->value;
switch (strtolower($attribute->name)) {
- case 'style':
- $styles = self::parseStyle($attribute, $styles);
-
- break;
case 'align':
$styles['alignment'] = self::mapAlign(trim($val));
@@ -152,6 +148,11 @@ protected static function parseInlineStyle($node, $styles = [])
break;
}
}
+
+ $attributeStyle = $attributes->getNamedItem('style');
+ if ($attributeStyle) {
+ $styles = self::parseStyle($attributeStyle, $styles);
+ }
}
return $styles;
diff --git a/tests/PhpWordTests/Shared/HtmlTest.php b/tests/PhpWordTests/Shared/HtmlTest.php
index 69e34ed927..cd2338e18e 100644
--- a/tests/PhpWordTests/Shared/HtmlTest.php
+++ b/tests/PhpWordTests/Shared/HtmlTest.php
@@ -19,6 +19,7 @@
use Exception;
use PhpOffice\PhpWord\Element\Section;
+use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\Html;
use PhpOffice\PhpWord\SimpleType\Jc;
use PhpOffice\PhpWord\SimpleType\LineSpacingRule;
@@ -41,7 +42,7 @@ public function testAddHtml(): void
$content = '';
// Default
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
self::assertCount(0, $section->getElements());
@@ -97,7 +98,7 @@ public function testParseFullHtml(): void
public function testParseHtmlEntities(): void
{
\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
Html::addHtml($section, 'text with entities <my text>');
@@ -112,7 +113,7 @@ public function testParseHtmlEntities(): void
public function testParseUnderline(): void
{
$html = 'test';
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
Html::addHtml($section, $html);
@@ -127,7 +128,7 @@ public function testParseUnderline(): void
public function testParseTextDecoration(): void
{
$html = 'test';
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
Html::addHtml($section, $html);
@@ -142,7 +143,7 @@ public function testParseTextDecoration(): void
public function testParseFont(): void
{
$html = 'test';
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
Html::addHtml($section, $html);
@@ -156,7 +157,7 @@ public function testParseFont(): void
*/
public function testParseLineHeight(): void
{
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
Html::addHtml($section, '
test
');
Html::addHtml($section, '
test
');
@@ -191,7 +192,7 @@ public function testParseLineHeight(): void
*/
public function testParseTextIndent(): void
{
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
Html::addHtml($section, '
test
');
@@ -205,7 +206,7 @@ public function testParseTextIndent(): void
*/
public function testParseTextAlign(): void
{
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
Html::addHtml($section, '
test
');
Html::addHtml($section, '
test
');
@@ -225,7 +226,7 @@ public function testParseTextAlign(): void
*/
public function testParseFontSize(): void
{
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
Html::addHtml($section, 'test');
Html::addHtml($section, 'test');
@@ -241,7 +242,7 @@ public function testParseFontSize(): void
*/
public function testParseTextDirection(): void
{
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
Html::addHtml($section, 'test');
@@ -254,7 +255,7 @@ public function testParseTextDirection(): void
*/
public function testParseLang(): void
{
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
Html::addHtml($section, 'test');
@@ -268,7 +269,7 @@ public function testParseLang(): void
*/
public function testParseFontFamily(): void
{
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
Html::addHtml($section, 'test');
Html::addHtml($section, 'test');
@@ -284,7 +285,7 @@ public function testParseFontFamily(): void
*/
public function testParseParagraphAndSpanStyle(): void
{
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
Html::addHtml($section, '
test
');
@@ -300,7 +301,7 @@ public function testParseParagraphAndSpanStyle(): void
*/
public function testParseParagraphWithPageBreak(): void
{
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
Html::addHtml($section, '');
@@ -314,7 +315,7 @@ public function testParseParagraphWithPageBreak(): void
*/
public function testParseTable(): void
{
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
$html = '
@@ -355,12 +356,81 @@ public function testParseTable(): void
self::assertFalse($doc->elementExists('/w:document/w:body/w:tbl/w:tr[1]/w:tc[2]/w:p/w:pPr/w:pBdr'));
}
+ /**
+ * Parse widths in tables and cells, which also allows for controlling column width.
+ */
+ public function testParseTableAndCellWidth(): void
+ {
+ $phpWord = new PhpWord();
+ $section = $phpWord->addSection([
+ 'orientation' => \PhpOffice\PhpWord\Style\Section::ORIENTATION_LANDSCAPE,
+ ]);
+
+ // borders & backgrounds are here just for better visual comparison
+ $html = <<
+
@@ -418,7 +558,7 @@ public function testParseList(): void
*/
public function testOrderedListNumbering(): void
{
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
$html = '
List 1 item 1
@@ -450,7 +590,7 @@ public function testOrderedListNumbering(): void
*/
public function testOrderedNestedListNumbering(): void
{
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
$html = '
List 1 item 1
@@ -487,7 +627,7 @@ public function testOrderedNestedListNumbering(): void
*/
public function testParseListWithFormat(): void
{
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
$html = preg_replace('/\s+/', ' ', '
Some text before
@@ -517,7 +657,7 @@ public function testParseListWithFormat(): void
*/
public function testParseLineBreak(): void
{
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
$html = '
This is some text with a linebreak.
';
Html::addHtml($section, $html);
@@ -537,7 +677,7 @@ public function testParseImage(): void
{
$src = __DIR__ . '/../_files/images/firefox.png';
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
$html = '
';
Html::addHtml($section, $html);
@@ -559,7 +699,7 @@ public function testParseRemoteImage(): void
{
$src = self::getRemoteImageUrl();
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
$html = '
';
Html::addHtml($section, $html);
@@ -575,7 +715,7 @@ public function testParseRemoteImage(): void
*/
public function testParseEmbeddedImage(): void
{
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
$html = '
';
Html::addHtml($section, $html);
@@ -598,7 +738,7 @@ public function testParseRemoteLocalImage(): void
'IMG_SRC_REPLACE' => $localPath,
];
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
$html = '
';
Html::addHtml($section, $html, false, true, $options);
@@ -617,7 +757,7 @@ public function testCouldNotLoadImage(): void
$this->expectException(Exception::class);
$src = 'https://fakedomain.io/images/firefox.png';
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
$html = '
';
Html::addHtml($section, $html, false, true);
@@ -625,7 +765,7 @@ public function testCouldNotLoadImage(): void
public function testParseLink(): void
{
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
$html = '
';
@@ -651,7 +791,7 @@ public function testParseLink(): void
public function testParseMalformedStyleIsIgnored(): void
{
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
$html = '
text
';
Html::addHtml($section, $html);
@@ -664,7 +804,7 @@ public function testParseMalformedStyleIsIgnored(): void
*/
public function testParseHiddenText(): void
{
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
$html = '
This is some hidden text.
';
Html::addHtml($section, $html);
@@ -679,7 +819,7 @@ public function testParseHiddenText(): void
*/
public function testParseLetterSpacing(): void
{
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
$html = '
This is some text with letter spacing.
';
Html::addHtml($section, $html);
@@ -695,7 +835,7 @@ public function testParseLetterSpacing(): void
*/
public function testInputCheckbox(): void
{
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
+ $phpWord = new PhpWord();
$section = $phpWord->addSection();
$html = '';
Html::addHtml($section, $html);
@@ -709,122 +849,12 @@ public function testInputCheckbox(): void
self::assertEquals(0, $doc->getElement('/w:document/w:body/w:p[2]/w:r/w:fldChar/w:ffData/w:checkBox/w:checked')->getAttribute('w:val'));
}
- /**
- * Parse widths in tables and cells, which also allows for controlling column width.
- */
- public function testParseTableAndCellWidth(): void
- {
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
- $section = $phpWord->addSection([
- 'orientation' => \PhpOffice\PhpWord\Style\Section::ORIENTATION_LANDSCAPE,
- ]);
-
- // borders & backgrounds are here just for better visual comparison
- $html = <<
-