Skip to content

Commit 0f793a5

Browse files
committed
Add <li value> support, fix list-style-type:square's wrong glyph
<li value="N"> (a WHATWG HTML presentational hint) had no effect on GetIndexForList's numbering - only <ol start>/reversed were consulted. Later items without their own explicit value now continue counting from a value-carrying item, matching every browser. Also fixes list-style-type:square rendering "♠" (U+2660 BLACK SPADE SUIT card-suit glyph) instead of an actual square - presumably a copy/paste typo, noticed while auditing this code for the counter port above. Re-approves the Bullets.png baseline for the corrected marker glyph. Ports the CSS2.1-relevant subset of PeachPDF's ListItemCounterIntegrationTests.cs (ol start/reversed were already correct; li value and the marker-glyph fix are new).
1 parent 9911bd2 commit 0f793a5

3 files changed

Lines changed: 83 additions & 1 deletion

File tree

‎Source/HtmlRenderer/Core/Dom/CssBox.cs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,15 @@ private int GetIndexForList()
12271227

12281228
foreach (CssBox b in ParentBox.Boxes)
12291229
{
1230+
// An explicit <li value="N"> (WHATWG HTML presentational hint) sets the running count to
1231+
// N for that item; later items (without their own explicit value) continue incrementing
1232+
// from there, matching every browser's actual behavior.
1233+
int explicitValue;
1234+
if (b.Display == CssConstants.ListItem && int.TryParse(b.GetAttribute("value"), out explicitValue))
1235+
{
1236+
index = explicitValue;
1237+
}
1238+
12301239
if (b.Equals(this))
12311240
return index;
12321241

@@ -1262,7 +1271,10 @@ private void CreateListItemBox(RGraphics g)
12621271
}
12631272
else if (ListStyleType.Equals(CssConstants.Square, StringComparison.InvariantCultureIgnoreCase))
12641273
{
1265-
_listItemBox.Text = "♠";
1274+
// Was "♠" (U+2660 BLACK SPADE SUIT) - not what CSS2.1 §12.5.1's list-style-type:
1275+
// square means at all (a filled square marker, the ♣/♦/♠ card-suit glyph was
1276+
// presumably a typo/copy-paste of a nearby symbol).
1277+
_listItemBox.Text = "▪"; // U+25AA BLACK SMALL SQUARE
12661278
}
12671279
else if (ListStyleType.Equals(CssConstants.Decimal, StringComparison.InvariantCultureIgnoreCase))
12681280
{
-171 Bytes
Loading
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System.Linq;
2+
using HtmlRenderer.IntegrationTest.TestSupport;
3+
4+
namespace HtmlRenderer.IntegrationTest.Content;
5+
6+
/// <summary>
7+
/// Ported from PeachPDF.Tests/Integration/ListItemCounterIntegrationTests.cs - the CSS2.1-relevant subset
8+
/// this fork's simpler, non-CSS-counter-driven list-marker mechanism (<c>CssBox.GetIndexForList</c>) can
9+
/// support: <c>&lt;ol start&gt;</c>/<c>reversed</c> (already implemented) and <c>&lt;li value&gt;</c> (newly
10+
/// added by this port). CSS3 marker-styling extras from the source file are not ported.
11+
/// </summary>
12+
[DoNotParallelize]
13+
[TestClass]
14+
public sealed class ListItemCounterIntegrationTests
15+
{
16+
[TestMethod]
17+
public void OlStart_OffsetsEveryItem()
18+
{
19+
var html = LayoutHarness.Wrap("<ol start='5'><li id='a'>x</li><li id='b'>y</li></ol>");
20+
var (root, _) = LayoutHarness.Layout(html);
21+
22+
var a = LayoutHarness.FindById(root, "a")!;
23+
var b = LayoutHarness.FindById(root, "b")!;
24+
25+
Assert.AreEqual("5.", a.ListItemBox.Words[0].Text);
26+
Assert.AreEqual("6.", b.ListItemBox.Words[0].Text);
27+
}
28+
29+
[TestMethod]
30+
public void OlReversed_CountsDownFromItemCount()
31+
{
32+
var html = LayoutHarness.Wrap("<ol reversed='reversed'><li id='a'>x</li><li id='b'>y</li><li id='c'>z</li></ol>");
33+
var (root, _) = LayoutHarness.Layout(html);
34+
35+
var a = LayoutHarness.FindById(root, "a")!;
36+
var b = LayoutHarness.FindById(root, "b")!;
37+
var c = LayoutHarness.FindById(root, "c")!;
38+
39+
Assert.AreEqual("3.", a.ListItemBox.Words[0].Text);
40+
Assert.AreEqual("2.", b.ListItemBox.Words[0].Text);
41+
Assert.AreEqual("1.", c.ListItemBox.Words[0].Text);
42+
}
43+
44+
[TestMethod]
45+
public void LiValue_OverridesThatItemAndContinuesFromThere()
46+
{
47+
var html = LayoutHarness.Wrap(
48+
"<ol><li id='a'>x</li><li id='b' value='10'>y</li><li id='c'>z</li></ol>");
49+
var (root, _) = LayoutHarness.Layout(html);
50+
51+
var a = LayoutHarness.FindById(root, "a")!;
52+
var b = LayoutHarness.FindById(root, "b")!;
53+
var c = LayoutHarness.FindById(root, "c")!;
54+
55+
Assert.AreEqual("1.", a.ListItemBox.Words[0].Text);
56+
Assert.AreEqual("10.", b.ListItemBox.Words[0].Text);
57+
Assert.AreEqual("11.", c.ListItemBox.Words[0].Text);
58+
}
59+
60+
[TestMethod]
61+
public void ListStyleTypeSquare_UsesAFilledSquareGlyph_NotASpadeSuitSymbol()
62+
{
63+
// Regression: this used to render "♠" (U+2660 BLACK SPADE SUIT), not a square at all.
64+
var html = LayoutHarness.Wrap("<ul style='list-style-type:square'><li id='a'>x</li></ul>");
65+
var (root, _) = LayoutHarness.Layout(html);
66+
var a = LayoutHarness.FindById(root, "a")!;
67+
68+
Assert.AreEqual("▪", a.ListItemBox.Words[0].Text);
69+
}
70+
}

0 commit comments

Comments
 (0)