diff --git a/testdata/TestCommonmark/list/goldmark.golden b/testdata/TestCommonmark/list/goldmark.golden
index 1cb0d00..5b934f2 100644
--- a/testdata/TestCommonmark/list/goldmark.golden
+++ b/testdata/TestCommonmark/list/goldmark.golden
@@ -75,7 +75,65 @@
22
+
+10
+
+
+11
+
+
+12
+
+
+13
+
+
+1
+
+
+2
+
+
+3
+
+
+4
+
+
+1
+
+
+2
+
+
+3
+
+
+4
+
+
+0
+
+
+1
+
+
+2
+
+
+3
+
+
+Echo the word "foo"
+
+echo('foo')
+
+
+- Now echo "bar"
+
+echo('bar')
+
-
Link: example works
diff --git a/testdata/TestCommonmark/list/input.html b/testdata/TestCommonmark/list/input.html
index ad4b5d8..e35e68d 100644
--- a/testdata/TestCommonmark/list/input.html
+++ b/testdata/TestCommonmark/list/input.html
@@ -44,6 +44,47 @@
+
+
+ - 10
+ - 11
+ - 12
+ - 13
+
+
+
+
+ - 1
+ - 2
+ - 3
+ - 4
+
+
+
+
+ - 1
+ - 2
+ - 3
+ - 4
+
+
+
+
+ - 0
+ - 1
+ - 2
+ - 3
+
+
+
+
+
- Echo the word "foo"
+
echo('foo')
+
- Now echo "bar"
+
echo('bar')
+
+
+
- Link: example works
diff --git a/testdata/TestCommonmark/list/output.asterisks.golden b/testdata/TestCommonmark/list/output.asterisks.golden
index 6c1da4d..9f8fb88 100644
--- a/testdata/TestCommonmark/list/output.asterisks.golden
+++ b/testdata/TestCommonmark/list/output.asterisks.golden
@@ -27,6 +27,38 @@
24. ![](http://example.com/example.png)
25. 22
+10. 10
+11. 11
+12. 12
+13. 13
+
+1. 1
+2. 2
+3. 3
+4. 4
+
+1. 1
+2. 2
+3. 3
+4. 4
+
+0. 0
+1. 1
+2. 2
+3. 3
+
+3. Echo the word "foo"
+
+```
+echo('foo')
+```
+
+4. Now echo "bar"
+
+```
+echo('bar')
+```
+
* Link: [example](https://example.com) works
* Link:
[example](https://example.com)
diff --git a/testdata/TestCommonmark/list/output.dash.golden b/testdata/TestCommonmark/list/output.dash.golden
index 5d5c994..9029beb 100644
--- a/testdata/TestCommonmark/list/output.dash.golden
+++ b/testdata/TestCommonmark/list/output.dash.golden
@@ -27,6 +27,38 @@
24. ![](http://example.com/example.png)
25. 22
+10. 10
+11. 11
+12. 12
+13. 13
+
+1. 1
+2. 2
+3. 3
+4. 4
+
+1. 1
+2. 2
+3. 3
+4. 4
+
+0. 0
+1. 1
+2. 2
+3. 3
+
+3. Echo the word "foo"
+
+```
+echo('foo')
+```
+
+4. Now echo "bar"
+
+```
+echo('bar')
+```
+
- Link: [example](https://example.com) works
- Link:
[example](https://example.com)
diff --git a/testdata/TestCommonmark/list/output.plus.golden b/testdata/TestCommonmark/list/output.plus.golden
index 7d75049..650c5c0 100644
--- a/testdata/TestCommonmark/list/output.plus.golden
+++ b/testdata/TestCommonmark/list/output.plus.golden
@@ -27,6 +27,38 @@
24. ![](http://example.com/example.png)
25. 22
+10. 10
+11. 11
+12. 12
+13. 13
+
+1. 1
+2. 2
+3. 3
+4. 4
+
+1. 1
+2. 2
+3. 3
+4. 4
+
+0. 0
+1. 1
+2. 2
+3. 3
+
+3. Echo the word "foo"
+
+```
+echo('foo')
+```
+
+4. Now echo "bar"
+
+```
+echo('bar')
+```
+
+ Link: [example](https://example.com) works
+ Link:
[example](https://example.com)
diff --git a/utils.go b/utils.go
index d3747ad..09bb3b3 100644
--- a/utils.go
+++ b/utils.go
@@ -359,6 +359,26 @@ func isWrapperListItem(s *goquery.Selection) bool {
return noOwnText && childIsList
}
+// getListStart returns the integer from which the counting
+// for for the list items should start from.
+// -> https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ol#start
+func getListStart(parent *goquery.Selection) int {
+ val := parent.AttrOr("start", "")
+ if val == "" {
+ return 1
+ }
+
+ num, err := strconv.Atoi(val)
+ if err != nil {
+ return 1
+ }
+
+ if num < 0 {
+ return 1
+ }
+ return num
+}
+
// getListPrefix returns the appropriate prefix for the list item.
// For example "- ", "* ", "1. ", "01. ", ...
func getListPrefix(opt *Options, s *goquery.Selection) string {
@@ -370,7 +390,8 @@ func getListPrefix(opt *Options, s *goquery.Selection) string {
if parent.Is("ul") {
return opt.BulletListMarker + " "
} else if parent.Is("ol") {
- currentIndex := s.Index() + 1
+ start := getListStart(parent)
+ currentIndex := start + s.Index()
lastIndex := parent.Children().Last().Index() + 1
maxLength := len(strconv.Itoa(lastIndex))