Fix listitem parsing (#1290)
* Word 2007 Reader: Added support for ListItemRun * Add tests + changelog
This commit is contained in:
parent
def023752d
commit
59de019881
|
|
@ -12,6 +12,7 @@ v0.15.0 (?? ??? 2018)
|
||||||
- Add support for Track changes @Cip @troosan #354 #1262
|
- Add support for Track changes @Cip @troosan #354 #1262
|
||||||
- Add support for fixed Table Layout @aoloe @ekopach @troosan #841 #1276
|
- Add support for fixed Table Layout @aoloe @ekopach @troosan #841 #1276
|
||||||
- Add support for Cell Spacing @dox07 @troosan #1040
|
- Add support for Cell Spacing @dox07 @troosan #1040
|
||||||
|
- Add parsing of formatting inside lists @atomicalnet @troosan #594
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Fix reading of docx default style - @troosan #1238
|
- Fix reading of docx default style - @troosan #1238
|
||||||
|
|
@ -22,6 +23,8 @@ v0.15.0 (?? ??? 2018)
|
||||||
- Bookmark are not writton as internal link in html writer @troosan #1263
|
- Bookmark are not writton as internal link in html writer @troosan #1263
|
||||||
- It should be possible to add a Footnote in a ListItemRun @troosan #1287 #1287
|
- It should be possible to add a Footnote in a ListItemRun @troosan #1287 #1287
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Remove zend-stdlib dependency @Trainmaster #1284
|
||||||
|
|
||||||
|
|
||||||
v0.14.0 (29 Dec 2017)
|
v0.14.0 (29 Dec 2017)
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -138,14 +138,15 @@ abstract class AbstractPart
|
||||||
$parent->addPreserveText($textContent, $fontStyle, $paragraphStyle);
|
$parent->addPreserveText($textContent, $fontStyle, $paragraphStyle);
|
||||||
} elseif ($xmlReader->elementExists('w:pPr/w:numPr', $domNode)) {
|
} elseif ($xmlReader->elementExists('w:pPr/w:numPr', $domNode)) {
|
||||||
// List item
|
// List item
|
||||||
$textContent = '';
|
|
||||||
$numId = $xmlReader->getAttribute('w:val', $domNode, 'w:pPr/w:numPr/w:numId');
|
$numId = $xmlReader->getAttribute('w:val', $domNode, 'w:pPr/w:numPr/w:numId');
|
||||||
$levelId = $xmlReader->getAttribute('w:val', $domNode, 'w:pPr/w:numPr/w:ilvl');
|
$levelId = $xmlReader->getAttribute('w:val', $domNode, 'w:pPr/w:numPr/w:ilvl');
|
||||||
$nodes = $xmlReader->getElements('w:r', $domNode);
|
$nodes = $xmlReader->getElements('*', $domNode);
|
||||||
|
|
||||||
|
$listItemRun = $parent->addListItemRun($levelId, "PHPWordList{$numId}", $paragraphStyle);
|
||||||
|
|
||||||
foreach ($nodes as $node) {
|
foreach ($nodes as $node) {
|
||||||
$textContent .= $xmlReader->getValue('w:t', $node);
|
$this->readRun($xmlReader, $node, $listItemRun, $docPart, $paragraphStyle);
|
||||||
}
|
}
|
||||||
$parent->addListItem($textContent, $levelId, null, "PHPWordList{$numId}", $paragraphStyle);
|
|
||||||
} elseif (!empty($headingMatches)) {
|
} elseif (!empty($headingMatches)) {
|
||||||
// Heading
|
// Heading
|
||||||
$textContent = '';
|
$textContent = '';
|
||||||
|
|
|
||||||
|
|
@ -43,4 +43,44 @@ class ElementTest extends AbstractTestReader
|
||||||
$this->assertInstanceOf('PhpOffice\PhpWord\Element\Text', $elements[1]);
|
$this->assertInstanceOf('PhpOffice\PhpWord\Element\Text', $elements[1]);
|
||||||
$this->assertEquals('test string', $elements[1]->getText());
|
$this->assertEquals('test string', $elements[1]->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test reading of textbreak
|
||||||
|
*/
|
||||||
|
public function testReadListItemRunWithFormatting()
|
||||||
|
{
|
||||||
|
$documentXml = '<w:p>
|
||||||
|
<w:pPr>
|
||||||
|
<w:numPr>
|
||||||
|
<w:ilvl w:val="0"/>
|
||||||
|
<w:numId w:val="11"/>
|
||||||
|
</w:numPr>
|
||||||
|
</w:pPr>
|
||||||
|
<w:r>
|
||||||
|
<w:t>Two</w:t>
|
||||||
|
</w:r>
|
||||||
|
<w:r>
|
||||||
|
<w:t xml:space="preserve"> with </w:t>
|
||||||
|
</w:r>
|
||||||
|
<w:r>
|
||||||
|
<w:rPr>
|
||||||
|
<w:b/>
|
||||||
|
</w:rPr>
|
||||||
|
<w:t>bold</w:t>
|
||||||
|
</w:r>
|
||||||
|
</w:p>';
|
||||||
|
|
||||||
|
$phpWord = $this->getDocumentFromString($documentXml);
|
||||||
|
|
||||||
|
$elements = $this->get($phpWord->getSections(), 0)->getElements();
|
||||||
|
$this->assertInstanceOf('PhpOffice\PhpWord\Element\ListItemRun', $elements[0]);
|
||||||
|
$this->assertEquals(0, $elements[0]->getDepth());
|
||||||
|
|
||||||
|
$listElements = $this->get($elements, 0)->getElements();
|
||||||
|
$this->assertInstanceOf('PhpOffice\PhpWord\Element\Text', $listElements[0]);
|
||||||
|
$this->assertEquals('Two', $listElements[0]->getText());
|
||||||
|
$this->assertEquals(' with ', $listElements[1]->getText());
|
||||||
|
$this->assertEquals('bold', $listElements[2]->getText());
|
||||||
|
$this->assertTrue($listElements[2]->getFontStyle()->getBold());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue