Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions examples/Demo/Resources/CompleteRunTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,34 @@ <h5>Heading 5</h5>
<li>Wine</li>
</ol>

<p>An Ordered List with Greek numbering: </p>
<ol style="list-style-type: upper-greek">
<li>alpha</li>
<li>
beta
<ol style="list-style-type: lower-greek">
<li>two.one</li>
<li>two.two</li>
<li>two.three</li>
</ol>
</li>

<li>
three
<ol style="list-style-type: lower-greek">
<li>three.one</li>
<li>
three.two
<ol>
<li>three.two.one</li>
<li>three.two.two</li>
</ol>
</li>
</ol>
</li>
<li>four</li>
</ol>

<table border=1><tr><td>Inside table</td></tr></table>
<hr />
<p>delta parameter (<span style='font-family:Symbol'>d</span>)</p>
Expand Down
27 changes: 27 additions & 0 deletions examples/Demo/Resources/NumberingList.htm
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,30 @@
</li>
<li>four</li>
</ol>

<ol style="list-style-type: upper-greek">
<li>one</li>
<li>
two
<ol style="list-style-type: lower-greek">
<li>two.one</li>
<li>two.two</li>
<li>two.three</li>
</ol>
</li>

<li>
three
<ol style="list-style-type: lower-greek">
<li>three.one</li>
<li>
three.two
<ol>
<li>three.two.one</li>
<li>three.two.two</li>
</ol>
</li>
</ol>
</li>
<li>four</li>
</ol>
2 changes: 2 additions & 0 deletions src/Html2OpenXml/Expressions/Numbering/ListExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ readonly struct ListContext(string listName, int absNumId, int instanceId, int l
private static readonly HashSet<string> supportedListTypes =
["disc", "decimal", "square", "circle",
"lower-alpha", "upper-alpha", "lower-latin", "upper-latin",
"lower-greek", "upper-greek",
"lower-roman", "upper-roman",
"decimal-tiered" /* not W3C compliant */];
private ParagraphStyleId? listParagraphStyleId;
Expand Down Expand Up @@ -243,6 +244,7 @@ private static string GetListName(IElement listNode, string? parentName = null)
"A" => "upper-alpha",
"i" => "lower-roman",
"I" => "upper-roman",
"lower-greek" or "upper-greek" => type,
_ => null
};

Expand Down
56 changes: 54 additions & 2 deletions test/HtmlToOpenXml.Tests/NumberingTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using NUnit.Framework;
using NUnit.Framework;
using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml.Packaging;

Expand Down Expand Up @@ -649,5 +649,57 @@ public void NestedTable_ReturnsAlignedTable()
Assert.That(Convert.ToInt32(tableProperties.TableWidth.Width.Value), Is.GreaterThan(0).And.LessThan(5000));
}
}

[Test]
public async Task LowerGreekList_ReturnsListWithGreekNumbering()
{
await converter.ParseBody(@"
<ol style='list-style-type: lower-greek'>
<li>Item 1</li>
<li>Item 2</li>
</ol>"
);

var elements = mainPart.Document!.Body!.Elements<Paragraph>().ToList();
Assert.That(elements, Has.Count.EqualTo(2));

var numbering = mainPart.NumberingDefinitionsPart!.Numbering!;
var absNum = numbering.Elements<AbstractNum>().SingleOrDefault();

Assert.That(absNum, Is.Not.Null);
Assert.That(absNum.AbstractNumDefinitionName?.Val?.Value, Is.EqualTo("lower-greek"));

var level = absNum.Elements<Level>().First();

using (Assert.EnterMultipleScope())
{
Assert.That(level.NumberingFormat?.Val?.Value, Is.EqualTo(NumberFormatValues.LowerLetter));
Assert.That(level.LevelText?.Val?.Value, Is.EqualTo("%1."));
}
}

[Test]
public async Task UpperGreekList_ReturnsListWithGreekNumbering()
{
await converter.ParseBody(@"
<ol style='list-style-type: upper-greek'>
<li>Item 1</li>
</ol>"
);

var numbering = mainPart.NumberingDefinitionsPart!.Numbering!;
var absNum = numbering.Elements<AbstractNum>().SingleOrDefault();

Assert.That(absNum, Is.Not.Null);
Assert.That(absNum.AbstractNumDefinitionName?.Val?.Value, Is.EqualTo("upper-greek"));

var level = absNum.Elements<Level>().First();

using (Assert.EnterMultipleScope())
{
Assert.That(level.NumberingFormat?.Val?.Value, Is.EqualTo(NumberFormatValues.UpperLetter));
Assert.That(level.LevelText?.Val?.Value, Is.EqualTo("%1."));
}
}
}
}
}