Skip to content
Open
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
3 changes: 2 additions & 1 deletion docs/changes/1.x/1.5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

## Enhancements
- Added support for image alt text by [@jwoodhead](https://github.com/jwoodhead) in [#2873](https://github.com/PHPOffice/PHPWord/pull/2873)
- HTML Reader: Support setting `keepLine` and `keepNext` on paragraphs by [@jwoodhead](https://github.com/jwoodhead) in [#2871](https://github.com/PHPOffice/PHPWord/pull/2871)

### Bug fixes

Expand All @@ -17,4 +18,4 @@

### BC Breaks

### Notes
### Notes
14 changes: 14 additions & 0 deletions src/PhpWord/Shared/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,20 @@ protected static function parseStyleDeclarations(array $selectors, array $styles
$styles['isPageBreak'] = true;
}

break;
case 'break-inside':
if ($value == 'avoid' || $value == 'avoid-page') {
$styles['keepLines'] = true;
}

break;
case 'break-after':
if ($value == 'avoid' || $value == 'avoid-page') {
$styles['keepNext'] = true;
} elseif ($value == 'always') {
$styles['isPageBreak'] = true;
}

break;
}
}
Expand Down
40 changes: 40 additions & 0 deletions tests/PhpWordTests/Shared/HtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,46 @@ public function testParseParagraphWithPageBreak(): void
self::assertEquals('page', $doc->getElementAttribute('/w:document/w:body/w:p/w:r/w:br', 'w:type'));
}

/**
* Test parsing paragraph with `break-inside: avoid` style.
*/
public function testParseParagraphWithBreakInsideAvoid(): void
{
$phpWord = new PhpWord();
$section = $phpWord->addSection();
Html::addHtml($section, '<p style="break-inside: avoid;"></p>');

$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
self::assertTrue($doc->elementExists('/w:document/w:body/w:p/w:pPr/w:keepLines'));
}

/**
* Test parsing paragraph with `break-after: avoid` style.
*/
public function testParseParagraphWithBreakAfterAvoid(): void
{
$phpWord = new PhpWord();
$section = $phpWord->addSection();
Html::addHtml($section, '<p style="break-after: avoid;"></p>');

$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
self::assertTrue($doc->elementExists('/w:document/w:body/w:p/w:pPr/w:keepNext'));
}

/**
* Test parsing paragraph with `break-after: always` style.
*/
public function testParseParagraphWithBreakAfterAlways(): void
{
$phpWord = new PhpWord();
$section = $phpWord->addSection();
Html::addHtml($section, '<p style="break-after: always;"></p>');

$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
self::assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:br'));
self::assertEquals('page', $doc->getElementAttribute('/w:document/w:body/w:p/w:r/w:br', 'w:type'));
}

/**
* Test parsing table.
*/
Expand Down
Loading