Skip to content

Commit c0ed4ab

Browse files
committed
Merge remote-tracking branch 'samimussbach/PHPWord/fixNestedLists' into various_html_parsing_fixes
2 parents 304173c + 8a9a478 commit c0ed4ab

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

samples/Sample_26_Html.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@
3131
<ol>
3232
<li>List 2 item 1</li>
3333
<li>List 2 item 2</li>
34-
<ol>
35-
<li>sub list 1</li>
36-
<li>sub list 2</li>
37-
</ol>
34+
<li>
35+
<ol>
36+
<li>sub list 1</li>
37+
<li>sub list 2</li>
38+
</ol>
39+
</li>
40+
3841
<li>List 2 item 3</li>
3942
<ol>
4043
<li>sub list 1, restarts with a</li>

tests/PhpWord/Shared/HtmlTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,43 @@ public function testOrderedListNumbering()
299299
$this->assertNotEquals($firstListnumId, $secondListnumId);
300300
}
301301

302+
/**
303+
* Tests parsing of nested ul/li
304+
*/
305+
public function testOrderedNestedListNumbering()
306+
{
307+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
308+
$section = $phpWord->addSection();
309+
$html = '<ol>
310+
<li>List 1 item 1</li>
311+
<li>List 1 item 2</li>
312+
</ol>
313+
<p>Some Text</p>
314+
<ol>
315+
<li>List 2 item 1</li>
316+
<li>
317+
<ol>
318+
<li>sub list 1</li>
319+
<li>sub list 2</li>
320+
</ol>
321+
</li>
322+
</ol>';
323+
Html::addHtml($section, $html, false, false);
324+
325+
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
326+
echo $doc->printXml();
327+
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:pPr/w:numPr/w:numId'));
328+
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:t'));
329+
330+
$this->assertEquals('List 1 item 1', $doc->getElement('/w:document/w:body/w:p[1]/w:r/w:t')->nodeValue);
331+
$this->assertEquals('List 2 item 1', $doc->getElement('/w:document/w:body/w:p[4]/w:r/w:t')->nodeValue);
332+
333+
$firstListnumId = $doc->getElementAttribute('/w:document/w:body/w:p[1]/w:pPr/w:numPr/w:numId', 'w:val');
334+
$secondListnumId = $doc->getElementAttribute('/w:document/w:body/w:p[4]/w:pPr/w:numPr/w:numId', 'w:val');
335+
336+
$this->assertNotEquals($firstListnumId, $secondListnumId);
337+
}
338+
302339
/**
303340
* Tests parsing of ul/li
304341
*/

0 commit comments

Comments
 (0)