Skip to content

Commit 8f512bf

Browse files
committed
Merge branch 'develop-html-br' of https://github.com/anrikun/PHPWord
into develop Conflicts: src/PhpWord/Shared/Html.php
2 parents b4b87cd + f7afdeb commit 8f512bf

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/PhpWord/Shared/Html.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ protected static function parseNode($node, $element, $styles = array(), $data =
136136
'ul' => array('List', null, null, $styles, $data, 3, null),
137137
'ol' => array('List', null, null, $styles, $data, 7, null),
138138
'li' => array('ListItem', $node, $element, $styles, $data, null, null),
139+
'br' => array('LineBreak', null, $element, $styles, null, null, null),
139140
);
140141

141142
$newElement = null;
@@ -523,4 +524,14 @@ private static function mapBorderStyle($cssBorderStyle)
523524
return 'single';
524525
}
525526
}
526-
}
527+
528+
/**
529+
* Parse line break
530+
*
531+
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
532+
*/
533+
private static function parseLineBreak($element)
534+
{
535+
$element->addTextBreak();
536+
}
537+
}

tests/PhpWord/Shared/HtmlTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,22 @@ public function testParseList()
234234
$this->assertEquals('list item1', $doc->getElement('/w:document/w:body/w:p[1]/w:r/w:t')->nodeValue);
235235
$this->assertEquals('list item2', $doc->getElement('/w:document/w:body/w:p[2]/w:r/w:t')->nodeValue);
236236
}
237+
238+
/**
239+
* Tests parsing of br
240+
*/
241+
public function testParseLineBreak()
242+
{
243+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
244+
$section = $phpWord->addSection();
245+
$html = '<p>This is some text<br/>with a linebreak.</p>';
246+
Html::addHtml($section, $html);
247+
248+
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
249+
250+
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:br'));
251+
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:t'));
252+
$this->assertEquals('This is some text', $doc->getElement('/w:document/w:body/w:p/w:r[1]/w:t')->nodeValue);
253+
$this->assertEquals('with a linebreak.', $doc->getElement('/w:document/w:body/w:p/w:r[2]/w:t')->nodeValue);
254+
}
237255
}

0 commit comments

Comments
 (0)