diff --git a/CHANGELOG.md b/CHANGELOG.md index 0752a42a..7dc8b458 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,8 @@ This is the last version to support PHP 5.3 - Support for Comments - @troosan #1067 - Support for paragraph textAlignment - @troosan #1165 - Add support for HTML underline tag in addHtml - @zNightFalLz #1186 -- Allow to change cell width unit - @guillaume-ro-fr #986 +- Add support for HTML
in addHtml - @anrikun @troosan #659 +- Allow to change cell width unit - guillaume-ro-fr #986 - Allow to change the line height rule @troosan - Implement PageBreak for odt writer @cookiekiller #863 #824 - Allow to force an update of all fields on opening a document - @troosan #951 diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php index 3f94e2ba..739bfb16 100644 --- a/src/PhpWord/Shared/Html.php +++ b/src/PhpWord/Shared/Html.php @@ -136,6 +136,7 @@ class Html 'ul' => array('List', null, null, $styles, $data, 3, null), 'ol' => array('List', null, null, $styles, $data, 7, null), 'li' => array('ListItem', $node, $element, $styles, $data, null, null), + 'br' => array('LineBreak', null, $element, $styles, null, null, null), ); $newElement = null; @@ -523,4 +524,14 @@ class Html return 'single'; } } + + /** + * Parse line break + * + * @param \PhpOffice\PhpWord\Element\AbstractContainer $element + */ + private static function parseLineBreak($element) + { + $element->addTextBreak(); + } } diff --git a/tests/PhpWord/Shared/HtmlTest.php b/tests/PhpWord/Shared/HtmlTest.php index 58b0d977..bfe24c58 100644 --- a/tests/PhpWord/Shared/HtmlTest.php +++ b/tests/PhpWord/Shared/HtmlTest.php @@ -234,4 +234,22 @@ class HtmlTest extends \PHPUnit\Framework\TestCase $this->assertEquals('list item1', $doc->getElement('/w:document/w:body/w:p[1]/w:r/w:t')->nodeValue); $this->assertEquals('list item2', $doc->getElement('/w:document/w:body/w:p[2]/w:r/w:t')->nodeValue); } + + /** + * Tests parsing of br + */ + public function testParseLineBreak() + { + $phpWord = new \PhpOffice\PhpWord\PhpWord(); + $section = $phpWord->addSection(); + $html = '

This is some text
with a linebreak.

'; + Html::addHtml($section, $html); + + $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); + + $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:br')); + $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:t')); + $this->assertEquals('This is some text', $doc->getElement('/w:document/w:body/w:p/w:r[1]/w:t')->nodeValue); + $this->assertEquals('with a linebreak.', $doc->getElement('/w:document/w:body/w:p/w:r[2]/w:t')->nodeValue); + } }