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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <u> in addHtml - @zNightFalLz #1186
- Allow to change cell width unit - @guillaume-ro-fr #986
- Add support for HTML <br> 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
Expand Down
11 changes: 11 additions & 0 deletions src/PhpWord/Shared/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ protected static function parseNode($node, $element, $styles = array(), $data =
'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;
Expand Down Expand Up @@ -523,4 +524,14 @@ private static function mapBorderStyle($cssBorderStyle)
return 'single';
}
}

/**
* Parse line break
*
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
*/
private static function parseLineBreak($element)
{
$element->addTextBreak();
}
}
18 changes: 18 additions & 0 deletions tests/PhpWord/Shared/HtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,22 @@ public function testParseList()
$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 = '<p>This is some text<br/>with a linebreak.</p>';
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);
}
}