diff --git a/CHANGELOG.md b/CHANGELOG.md index e64887ae..1b50e601 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,10 +12,11 @@ v0.15.0 (?? ??? 2018) - Add support for Track changes @Cip @troosan #354 #1262 ### Fixed -- fix reading of docx default style - @troosan #1238 -- fix the size unit of when parsing html images - @troosan #1254 -- fixed HTML parsing of nested lists - @troosan #1265 +- Fix reading of docx default style - @troosan #1238 +- Fix the size unit of when parsing html images - @troosan #1254 +- Fixed HTML parsing of nested lists - @troosan #1265 - Save PNG alpha information when using remote images. @samsullivan #779 +- fix parsing of `` tag. @troosan #1274 diff --git a/src/PhpWord/Reader/Word2007/AbstractPart.php b/src/PhpWord/Reader/Word2007/AbstractPart.php index 366bde7e..9276823b 100644 --- a/src/PhpWord/Reader/Word2007/AbstractPart.php +++ b/src/PhpWord/Reader/Word2007/AbstractPart.php @@ -94,7 +94,7 @@ abstract class AbstractPart * * @param \PhpOffice\Common\XMLReader $xmlReader * @param \DOMElement $domNode - * @param mixed $parent + * @param \PhpOffice\PhpWord\Element\AbstractContainer $parent * @param string $docPart * * @todo Get font style for preserve text @@ -180,7 +180,7 @@ abstract class AbstractPart * * @param \PhpOffice\Common\XMLReader $xmlReader * @param \DOMElement $domNode - * @param mixed $parent + * @param \PhpOffice\PhpWord\Element\AbstractContainer $parent * @param string $docPart * @param mixed $paragraphStyle * @@ -236,7 +236,11 @@ abstract class AbstractPart $textContent = "<Object: {$target}>"; $parent->addText($textContent, $fontStyle, $paragraphStyle); } - } else { + } + if ($xmlReader->elementExists('w:br', $domNode)) { + $parent->addTextBreak(); + } + if ($xmlReader->elementExists('w:t', $domNode)) { // TextRun if ($domNode->parentNode->nodeName == 'w:del') { $textContent = $xmlReader->getValue('w:delText', $domNode); diff --git a/tests/PhpWord/Reader/Word2007/ElementTest.php b/tests/PhpWord/Reader/Word2007/ElementTest.php new file mode 100644 index 00000000..67c2eb13 --- /dev/null +++ b/tests/PhpWord/Reader/Word2007/ElementTest.php @@ -0,0 +1,46 @@ + + + + test string + + '; + + $phpWord = $this->getDocumentFromString($documentXml); + + $elements = $this->get($phpWord->getSections(), 0)->getElements(); + $this->assertInstanceOf('PhpOffice\PhpWord\Element\TextBreak', $elements[0]); + $this->assertInstanceOf('PhpOffice\PhpWord\Element\Text', $elements[1]); + $this->assertEquals('test string', $elements[1]->getText()); + } +} diff --git a/tests/PhpWord/_includes/AbstractTestReader.php b/tests/PhpWord/_includes/AbstractTestReader.php new file mode 100644 index 00000000..f138ac76 --- /dev/null +++ b/tests/PhpWord/_includes/AbstractTestReader.php @@ -0,0 +1,59 @@ +open($file, \ZipArchive::CREATE); + $zip->addFromString('document.xml', '' . $documentXml . ''); + $zip->close(); + $documentReader = new Document($file, 'document.xml'); + $documentReader->read($phpWord); + unlink($file); + + return $phpWord; + } + + /** + * Returns the element at position $index in the array + * + * @param array $array + * @param number $index + * @return mixed + */ + protected function get(array $array, $index = 0) + { + return $array[$index]; + } +}