Hello,
phpdocx 8.5 added changes to the internal algorithm to handle that kind of nested list correctly.
Although we recommend you to upgrade to phpdocx 8.5 to get the latest improvements in the DOCX to HTML transformation feature (https://www.phpdocx.com/news/post/phpdocx-v8-5-release-notes/217), you can apply the following patch to use the numbering styles with nested lists:
@@ -1882,7 +1882,18 @@
// get w:numId to know the ID of the list
$numIdTag = $numPrTag->item(0)->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'numId');
if ($numIdTag->length > 0 && $numIdTag->item(0)->hasAttribute('w:val') && $numIdTag->item(0)->getAttribute('w:val') != '') {
+ // handle start list number
+ if (!isset($this->listStartValues[$numIdTag->item(0)->getAttribute('w:val')])) {
+ $this->listStartValues[$numIdTag->item(0)->getAttribute('w:val')] = array();
+ }
$numberingLevel = (int)$numPrTag->item(0)->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'ilvl')->item(0)->getAttribute('w:val');
+ // handle start list number
+ if (!isset($this->listStartValues[$numIdTag->item(0)->getAttribute('w:val')][$numberingLevel])) {
+ $this->listStartValues[$numIdTag->item(0)->getAttribute('w:val')][$numberingLevel] = 1;
+ } else {
+ $this->listStartValues[$numIdTag->item(0)->getAttribute('w:val')][$numberingLevel] = $this->listStartValues[$numIdTag->item(0)->getAttribute('w:val')][$numberingLevel] + 1;
+ }
+
// get the numbering style based on the numbering ID and its level
$numberingStyle = $this->getNumberingType($numIdTag->item(0)->getAttribute('w:val'), $numberingLevel);
@@ -2007,6 +2018,9 @@
$closeNewList = true;
}
+ // sets how many list levels must be closed
+ $iterationListClose = 1;
+
if ($nextSiblingElement !== null) {
$numPrNextSiblingElement = $nextSiblingElement->getElementsByTagNameNS('http://schemas.openxmlformats.org/wordprocessingml/2006/main', 'numPr');
if ($numPrNextSiblingElement->length > 0) {
@@ -2017,6 +2031,11 @@
// get the numbering style based on the numbering ID and its level
$numberingStyleNextSiblingElementTag = $this->getNumberingType($numIdNextSiblingElementTag->item(0)->getAttribute('w:val'), $numberingLevelNextSiblingElementTag);
+ // handle close list levels
+ if ($numberingLevel > 0 && $numIdNextSiblingElementTag->item(0)->getAttribute('w:val') != $numIdTag->item(0)->getAttribute('w:val')) {
+ $iterationListClose += $numberingLevel;
+ }
+
if ($numIdNextSiblingElementTag->item(0)->getAttribute('w:val') != $numIdTag->item(0)->getAttribute('w:val')) {
$closeNewList = true;
}
@@ -2026,8 +2045,13 @@
}
}
} else {
- // the next element is not a numbering, then create a new list
+ // the next element is not a numbering, then close the list
$closeNewList = true;
+
+ // handle close list levels
+ if ($numberingLevel > 0) {
+ $iterationListClose += $numberingLevel;
+ }
}
}
@@ -2039,7 +2063,9 @@
$tagTypeList = $this->htmlPlugin->getTag('unorderedList');
}
if ($closeNewList === true) {
- $this->html .= '</'.$tagTypeList.'>';
+ for ($iClose = 0; $iClose < $iterationListClose; $iClose++) {
+ $this->html .= '</'.$tagTypeList.'>';
+ }
}
}
}
If you send to contact[at]phpdocx.com an e-mail sending if you are using the classic or namespaces package, the dev team will send you the class updated with these changes.
Regards.