diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php index a2ea946524..63a0a113b2 100644 --- a/src/PhpWord/Shared/Html.php +++ b/src/PhpWord/Shared/Html.php @@ -257,14 +257,16 @@ protected static function parseChildNodes($node, $element, $styles, $data) * @param \DOMNode $node * @param \PhpOffice\PhpWord\Element\AbstractContainer $element * @param array &$styles - * @return \PhpOffice\PhpWord\Element\TextRun + * @return \PhpOffice\PhpWord\Element\TextRun|\PhpOffice\PhpWord\Element\PageBreak */ protected static function parseParagraph($node, $element, &$styles) { $styles['paragraph'] = self::recursiveParseStylesInHierarchy($node, $styles['paragraph']); - $newElement = $element->addTextRun($styles['paragraph']); + if (isset($styles['paragraph']['isPageBreak']) && $styles['paragraph']['isPageBreak']) { + return $element->addPageBreak(); + } - return $newElement; + return $element->addTextRun($styles['paragraph']); } /** @@ -771,6 +773,11 @@ protected static function parseStyle($attribute, $styles) $styles['valign'] = self::mapAlignVertical($matches[0]); } break; + case 'page-break-after': + if ($cValue == 'always') { + $styles['isPageBreak'] = true; + } + break; } } diff --git a/tests/PhpWord/Shared/HtmlTest.php b/tests/PhpWord/Shared/HtmlTest.php index 80f96d5773..eecec002dc 100644 --- a/tests/PhpWord/Shared/HtmlTest.php +++ b/tests/PhpWord/Shared/HtmlTest.php @@ -291,6 +291,20 @@ public function testParseParagraphAndSpanStyle() $this->assertEquals('single', $doc->getElementAttribute('/w:document/w:body/w:p[1]/w:r/w:rPr/w:u', 'w:val')); } + /** + * Test parsing paragraph with `page-break-after` style + */ + public function testParseParagraphWithPageBreak() + { + $phpWord = new \PhpOffice\PhpWord\PhpWord(); + $section = $phpWord->addSection(); + Html::addHtml($section, '

'); + + $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); + $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:br')); + $this->assertEquals('page', $doc->getElementAttribute('/w:document/w:body/w:p/w:r/w:br', 'w:type')); + } + /** * Test parsing table */ @@ -776,7 +790,7 @@ public function testParseCellspacingRowBgColor() /** * Parse horizontal rule */ - public function testParseHorizRule() + public function testParseHorizontalRule() { $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection();