sealed class NumberingListStyleCollection
{
//...
private int maxlevelDepth = 0;
//...
public void BeginList(HtmlEnumerator en)
{
int prevAbsNumId = absNumId;
// lookup for a predefined list style in the template collection
String type = en.StyleAttributes["list-style-type"];
bool orderedList = en.CurrentTag.Equals("
", StringComparison.OrdinalIgnoreCase);
if (type == null || !knonwAbsNumIds.TryGetValue(type.ToLowerInvariant(), out absNumId))
{
if (orderedList)
absNumId = knonwAbsNumIds["decimal"];
else
absNumId = knonwAbsNumIds["disc"];
}
firstItem = true;
levelDepth++;
// save a NumberingInstance if the nested list style is the same as its ancestor.
// this allows us to nest and restart the indentation to 1.
int currentInstanceId = this.InstanceID;
if (levelDepth > 1 && absNumId == prevAbsNumId && orderedList)
{
EnsureMultilevel(absNumId);
}
else
{
// For unordered lists (), create only one NumberingInstance per level
// (MS Word does not tolerate hundreds of identical NumberingInstances)
if (orderedList || (levelDepth > maxlevelDepth))
{
if (levelDepth > maxlevelDepth)
{
maxlevelDepth = levelDepth;
}
currentInstanceId = ++nextInstanceID;
Numbering numbering = mainPart.NumberingDefinitionsPart.Numbering;
numbering.Append(
new NumberingInstance(
new AbstractNumId() { Val = absNumId },
new LevelOverride(
new StartOverrideNumberingValue() { Val = 1 }
) { LevelIndex = 0, }
) { NumberID = currentInstanceId });
}
}
numInstances.Push(currentInstanceId);
}