diff --git a/CHANGELOG.md b/CHANGELOG.md
index 93945189..b5396d8d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,13 @@ Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
+v0.15.0 (?? ??? 2018)
+----------------------
+### Added
+- Parsing of "align" HTML attribute - @troosan
+
+### Fixed
+
v0.14.0 (29 Dec 2017)
----------------------
This release fixes several bugs and adds some new features.
diff --git a/samples/Sample_26_Html.php b/samples/Sample_26_Html.php
index ba06b063..b993f834 100644
--- a/samples/Sample_26_Html.php
+++ b/samples/Sample_26_Html.php
@@ -28,7 +28,7 @@ $html .= '
';
-$html .= '
+$html .= '
| header a |
diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php
index d8a10b57..38d326c1 100644
--- a/src/PhpWord/Shared/Html.php
+++ b/src/PhpWord/Shared/Html.php
@@ -85,6 +85,8 @@ class Html
case 'style':
$styles = self::parseStyle($attribute, $styles);
break;
+ case 'align':
+ $styles['alignment'] = self::mapAlign($attribute->value);
}
}
}
@@ -431,20 +433,7 @@ class Html
}
break;
case 'text-align':
- switch ($cValue) {
- case 'left':
- $styles['alignment'] = Jc::START;
- break;
- case 'right':
- $styles['alignment'] = Jc::END;
- break;
- case 'center':
- $styles['alignment'] = Jc::CENTER;
- break;
- case 'justify':
- $styles['alignment'] = Jc::BOTH;
- break;
- }
+ $styles['alignment'] = self::mapAlign($cValue);
break;
case 'font-size':
$styles['size'] = Converter::cssToPoint($cValue);
@@ -584,6 +573,28 @@ class Html
}
}
+ /**
+ * Transforms a HTML/CSS alignment into a \PhpOffice\PhpWord\SimpleType\Jc
+ *
+ * @param string $cssAlignment
+ * @return string|null
+ */
+ private static function mapAlign($cssAlignment)
+ {
+ switch ($cssAlignment) {
+ case 'left':
+ return Jc::START;
+ case 'right':
+ return Jc::END;
+ case 'center':
+ return Jc::CENTER;
+ case 'justify':
+ return Jc::BOTH;
+ }
+
+ return null;
+ }
+
/**
* Parse line break
*
diff --git a/tests/PhpWord/Shared/HtmlTest.php b/tests/PhpWord/Shared/HtmlTest.php
index d168c09e..c7d36470 100644
--- a/tests/PhpWord/Shared/HtmlTest.php
+++ b/tests/PhpWord/Shared/HtmlTest.php
@@ -187,7 +187,7 @@ class HtmlTest extends \PHPUnit\Framework\TestCase
{
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
- $html = '
+ $html = '
| header a |
@@ -205,6 +205,8 @@ class HtmlTest extends \PHPUnit\Framework\TestCase
$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:tr/w:tc'));
+ $this->assertTrue($doc->elementExists('/w:document/w:body/w:tbl/w:tblPr/w:jc'));
+ $this->assertEquals(Jc::START, $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tblPr/w:jc', 'w:val'));
}
/**