Skip to content

Commit bf8ca33

Browse files
authored
✨ NEW: Save ordered list numbering (#192)
1 parent d357240 commit bf8ca33

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

markdown_it/port.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
- package: markdown-it/markdown-it
2-
version: 12.1.0
3-
commit: e5986bb7cca20ac95dc81e4741c08949bf01bb77
4-
date: Jul 15, 2021
2+
version: 12.2.0
3+
commit: 6e2de08a0b03d3d0dcc524b89710ce05f83a0283
4+
date: Aug 2, 2021
55
notes:
66
- Rename variables that use python built-in names, e.g.
77
- `max` -> `maximum`

markdown_it/rules_block/list.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ def list_block(state: StateBlock, startLine: int, endLine: int, silent: bool):
230230
token = state.push("list_item_open", "li", 1)
231231
token.markup = chr(markerCharCode)
232232
token.map = itemLines = [startLine, 0]
233+
if isOrdered:
234+
token.info = state.src[start : posAfterMarker - 1]
233235

234236
# change current state, then restore it after parser subcall
235237
oldTight = state.tight
@@ -313,6 +315,7 @@ def list_block(state: StateBlock, startLine: int, endLine: int, silent: bool):
313315
posAfterMarker = skipOrderedListMarker(state, nextLine)
314316
if posAfterMarker < 0:
315317
break
318+
start = state.bMarks[nextLine] + state.tShift[nextLine]
316319
else:
317320
posAfterMarker = skipBulletListMarker(state, nextLine)
318321
if posAfterMarker < 0:

markdown_it/token.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Token:
5555
# Additional information:
5656
# - Info string for "fence" tokens
5757
# - The value "auto" for autolink "link_open" and "link_close" tokens
58+
# - The string value of the item marker for ordered-list "list_item_open" tokens
5859
info: str = attr.ib(default="")
5960
# A place for plugins to store any arbitrary data
6061
meta: dict = attr.ib(factory=dict)

tests/test_port/test_misc.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,34 @@ def highlight_func(str_, lang, attrs):
1212
conf["options"]["highlight"] = highlight_func
1313
md = MarkdownIt(config=conf)
1414
assert md.render("``` a b c d \nhl\n```") == "<pre><code>==hl\n==</code></pre>\n"
15+
16+
17+
def test_ordered_list_info():
18+
def type_filter(tokens, type_):
19+
return [t for t in tokens if t.type == type_]
20+
21+
md = MarkdownIt()
22+
23+
tokens = md.parse("1. Foo\n2. Bar\n20. Fuzz")
24+
assert len(type_filter(tokens, "ordered_list_open")) == 1
25+
tokens = type_filter(tokens, "list_item_open")
26+
assert len(tokens) == 3
27+
assert tokens[0].info == "1"
28+
assert tokens[0].markup == "."
29+
assert tokens[1].info == "2"
30+
assert tokens[1].markup == "."
31+
assert tokens[2].info == "20"
32+
assert tokens[2].markup == "."
33+
34+
tokens = md.parse(" 1. Foo\n2. Bar\n 20. Fuzz\n 199. Flp")
35+
assert len(type_filter(tokens, "ordered_list_open")) == 1
36+
tokens = type_filter(tokens, "list_item_open")
37+
assert len(tokens) == 4
38+
assert tokens[0].info == "1"
39+
assert tokens[0].markup == "."
40+
assert tokens[1].info == "2"
41+
assert tokens[1].markup == "."
42+
assert tokens[2].info == "20"
43+
assert tokens[2].markup == "."
44+
assert tokens[3].info == "199"
45+
assert tokens[3].markup == "."

0 commit comments

Comments
 (0)