(self->renderer.getFontAscenderSize(self->fontId));
@@ -1050,14 +1058,21 @@ void XMLCALL ChapterHtmlSlimParser::startElement(void* userData, const XML_Char*
self->updateEffectiveInlineStyle();
if (strcmp(name, "li") == 0) {
- char marker[12];
- if (!self->listStack.empty() && self->listStack.back().isOrdered) {
- self->listStack.back().counter += 1;
- snprintf(marker, sizeof(marker), "%d.", self->listStack.back().counter);
- } else {
- strcpy(marker, "\xe2\x80\xa2");
+ if (!self->listStack.empty()) {
+ char marker[12];
+ if (self->listStack.back().isOrdered) {
+ const char* valueAttr = getAttribute(atts, "value");
+ if (valueAttr) {
+ int v = atoi(valueAttr);
+ if (v > 0) self->listStack.back().counter = v - 1;
+ }
+ self->listStack.back().counter += 1;
+ snprintf(marker, sizeof(marker), "%d.", self->listStack.back().counter);
+ } else {
+ strcpy(marker, "\xe2\x80\xa2");
+ }
+ self->currentTextBlock->addWord(marker, EpdFontFamily::REGULAR);
}
- self->currentTextBlock->addWord(marker, EpdFontFamily::REGULAR);
} else if (strcmp(name, "pre") == 0) {
// Record depth so characterData can treat \n as a hard line break inside .
// depth has not been incremented yet here; it will be after startElement returns.
diff --git a/scripts/generate_test_epub.py b/scripts/generate_test_epub.py
index 76c199a5..1b12e1ff 100644
--- a/scripts/generate_test_epub.py
+++ b/scripts/generate_test_epub.py
@@ -1016,6 +1016,7 @@ def main():
pre with inline code element
horizontal rules between paragraphs
superscript and subscript rendering
+list rendering: ul, ol, nested, start/value attributes, bare li
""",
),
@@ -1086,6 +1087,88 @@ greet("World");
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
End of horizontal rule tests.
+""",
+ ),
+ [],
+ ),
+ (
+ "6. Lists",
+ make_chapter(
+ "List Rendering Tests",
+ """
+Unordered list (bullets)
+
+- First item
+- Second item
+- Third item
+
+
+Ordered list (numbers 1, 2, 3)
+
+- One
+- Two
+- Three
+
+
+Ordered list with start="5" (should begin at 5)
+
+- Five
+- Six
+- Seven
+
+
+Ordered list with li value override (should show 1, 2, 5, 6)
+
+- One
+- Two
+- Five
+- Six
+
+
+Nested lists
+
+- Fruit
+
+
+- Vegetables
+
+
+
+
+Nested ordered lists (outer 1,2 / inner 1,2,3)
+
+- Chapter one
+
+ - Section A
+ - Section B
+ - Section C
+
+
+- Chapter two
+
+ - Section A
+ - Section B
+
+
+
+
+Bare li outside any list (no bullet should appear)
+The line below is a bare <li> with no enclosing <ul> or <ol>. No bullet or number should appear before it.
+This bare li should have no marker
+Normal paragraph resumed.
+
+List with inline formatting
+
+- Bold item text
+- Italic item text
+- Item with bold and italic mixed
+
""",
),
[],
diff --git a/test/epubs/test_text_rendering.epub b/test/epubs/test_text_rendering.epub
index 74be4b31..95673e00 100644
Binary files a/test/epubs/test_text_rendering.epub and b/test/epubs/test_text_rendering.epub differ