HTML Reader : Style page-break-after in paragraph
This commit is contained in:
parent
be0190cd5d
commit
2de551647b
|
|
@ -257,14 +257,16 @@ class Html
|
||||||
* @param \DOMNode $node
|
* @param \DOMNode $node
|
||||||
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
|
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
|
||||||
* @param array &$styles
|
* @param array &$styles
|
||||||
* @return \PhpOffice\PhpWord\Element\TextRun
|
* @return \PhpOffice\PhpWord\Element\TextRun|\PhpOffice\PhpWord\Element\PageBreak
|
||||||
*/
|
*/
|
||||||
protected static function parseParagraph($node, $element, &$styles)
|
protected static function parseParagraph($node, $element, &$styles)
|
||||||
{
|
{
|
||||||
$styles['paragraph'] = self::recursiveParseStylesInHierarchy($node, $styles['paragraph']);
|
$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 @@ class Html
|
||||||
$styles['valign'] = self::mapAlignVertical($matches[0]);
|
$styles['valign'] = self::mapAlignVertical($matches[0]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'page-break-after':
|
||||||
|
if ($cValue == 'always') {
|
||||||
|
$styles['isPageBreak'] = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -291,6 +291,20 @@ class HtmlTest extends AbstractWebServerEmbeddedTest
|
||||||
$this->assertEquals('single', $doc->getElementAttribute('/w:document/w:body/w:p[1]/w:r/w:rPr/w:u', 'w:val'));
|
$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
|
* Test parsing table
|
||||||
*/
|
*/
|
||||||
|
|
@ -776,7 +790,7 @@ HTML;
|
||||||
/**
|
/**
|
||||||
* Parse horizontal rule
|
* Parse horizontal rule
|
||||||
*/
|
*/
|
||||||
public function testParseHorizRule()
|
public function testParseHorizontalRule()
|
||||||
{
|
{
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue