Merge branch 'develop-html-br' of https://github.com/anrikun/PHPWord

into develop

Conflicts:
	src/PhpWord/Shared/Html.php
This commit is contained in:
troosan 2017-12-05 17:33:51 +01:00
commit 8f512bf618
2 changed files with 30 additions and 1 deletions

View File

@ -136,6 +136,7 @@ class Html
'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;
@ -523,4 +524,14 @@ class Html
return 'single';
}
}
}
/**
* Parse line break
*
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
*/
private static function parseLineBreak($element)
{
$element->addTextBreak();
}
}

View File

@ -234,4 +234,22 @@ class HtmlTest extends \PHPUnit\Framework\TestCase
$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);
}
}