Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/PhpWord/Shared/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

/**
Expand Down Expand Up @@ -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;
}
}

Expand Down
16 changes: 15 additions & 1 deletion tests/PhpWord/Shared/HtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<p style="page-break-after:always;"></p>');

$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
*/
Expand Down Expand Up @@ -776,7 +790,7 @@ public function testParseCellspacingRowBgColor()
/**
* Parse horizontal rule
*/
public function testParseHorizRule()
public function testParseHorizontalRule()
{
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
Expand Down