Skip to content

✨ NEW: Save ordered list numbering #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 6, 2022
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
6 changes: 3 additions & 3 deletions markdown_it/port.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- package: markdown-it/markdown-it
version: 12.1.0
commit: e5986bb7cca20ac95dc81e4741c08949bf01bb77
date: Jul 15, 2021
version: 12.2.0
commit: 6e2de08a0b03d3d0dcc524b89710ce05f83a0283
date: Aug 2, 2021
notes:
- Rename variables that use python built-in names, e.g.
- `max` -> `maximum`
Expand Down
3 changes: 3 additions & 0 deletions markdown_it/rules_block/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ def list_block(state: StateBlock, startLine: int, endLine: int, silent: bool):
token = state.push("list_item_open", "li", 1)
token.markup = chr(markerCharCode)
token.map = itemLines = [startLine, 0]
if isOrdered:
token.info = state.src[start : posAfterMarker - 1]

# change current state, then restore it after parser subcall
oldTight = state.tight
Expand Down Expand Up @@ -313,6 +315,7 @@ def list_block(state: StateBlock, startLine: int, endLine: int, silent: bool):
posAfterMarker = skipOrderedListMarker(state, nextLine)
if posAfterMarker < 0:
break
start = state.bMarks[nextLine] + state.tShift[nextLine]
else:
posAfterMarker = skipBulletListMarker(state, nextLine)
if posAfterMarker < 0:
Expand Down
1 change: 1 addition & 0 deletions markdown_it/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Token:
# Additional information:
# - Info string for "fence" tokens
# - The value "auto" for autolink "link_open" and "link_close" tokens
# - The string value of the item marker for ordered-list "list_item_open" tokens
info: str = attr.ib(default="")
# A place for plugins to store any arbitrary data
meta: dict = attr.ib(factory=dict)
Expand Down
31 changes: 31 additions & 0 deletions tests/test_port/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,34 @@ def highlight_func(str_, lang, attrs):
conf["options"]["highlight"] = highlight_func
md = MarkdownIt(config=conf)
assert md.render("``` a b c d \nhl\n```") == "<pre><code>==hl\n==</code></pre>\n"


def test_ordered_list_info():
def type_filter(tokens, type_):
return [t for t in tokens if t.type == type_]

md = MarkdownIt()

tokens = md.parse("1. Foo\n2. Bar\n20. Fuzz")
assert len(type_filter(tokens, "ordered_list_open")) == 1
tokens = type_filter(tokens, "list_item_open")
assert len(tokens) == 3
assert tokens[0].info == "1"
assert tokens[0].markup == "."
assert tokens[1].info == "2"
assert tokens[1].markup == "."
assert tokens[2].info == "20"
assert tokens[2].markup == "."

tokens = md.parse(" 1. Foo\n2. Bar\n 20. Fuzz\n 199. Flp")
assert len(type_filter(tokens, "ordered_list_open")) == 1
tokens = type_filter(tokens, "list_item_open")
assert len(tokens) == 4
assert tokens[0].info == "1"
assert tokens[0].markup == "."
assert tokens[1].info == "2"
assert tokens[1].markup == "."
assert tokens[2].info == "20"
assert tokens[2].markup == "."
assert tokens[3].info == "199"
assert tokens[3].markup == "."