Skip to content

Commit ed4680d

Browse files
committed
Fix and add test for myst block token
1 parent 0ff53a0 commit ed4680d

File tree

5 files changed

+70
-6
lines changed

5 files changed

+70
-6
lines changed

markdown_it/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .main import MarkdownIt # noqa: F401
22

33

4-
__version__ = "0.4.2"
4+
__version__ = "0.4.3"

markdown_it/extensions/front_matter/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def frontMatter(state: StateBlock, startLine: int, endLine: int, silent: bool):
120120
state.parentType = old_parent
121121
state.lineMax = old_line_max
122122
state.line = nextLine + (1 if auto_closed else 0)
123-
token.map = [startLine, state.line - 1]
123+
token.map = [startLine, state.line]
124124

125125
return True
126126

markdown_it/extensions/myst_blocks/index.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ def block_break(state: StateBlock, startLine: int, endLine: int, silent: bool):
8282
cnt = 1
8383
while pos < maximum:
8484
ch = charCodeAt(state.src, pos)
85-
pos += 1
8685
if ch != marker and not isSpace(ch):
8786
break
8887
if ch == marker:
8988
cnt += 1
89+
pos += 1
9090

9191
if cnt < 3:
9292
return False
@@ -98,9 +98,9 @@ def block_break(state: StateBlock, startLine: int, endLine: int, silent: bool):
9898

9999
token = state.push("myst_block_break", "hr", 0)
100100
token.attrSet("class", "myst-block")
101-
token.content = state.src[pos - 1 : maximum].strip()
101+
token.content = state.src[pos:maximum].strip()
102102
token.map = [startLine, state.line]
103-
token.markup = chr(marker) * (cnt + 1)
103+
token.markup = chr(marker) * cnt
104104

105105
return True
106106

tests/test_front_matter/test_fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_token():
2929
tag="",
3030
nesting=0,
3131
attrs=None,
32-
map=[0, 2],
32+
map=[0, 3],
3333
level=0,
3434
children=None,
3535
content="a: 1",

tests/test_myst_block/test_fixtures.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44

55
from markdown_it import MarkdownIt
6+
from markdown_it.token import Token
67
from markdown_it.utils import read_fixture_file
78
from markdown_it.extensions.myst_blocks import myst_block_plugin
89

@@ -16,3 +17,66 @@ def test_all(line, title, input, expected):
1617
text = md.render(input)
1718
print(text)
1819
assert text.rstrip() == expected.rstrip()
20+
21+
22+
def test_block_token():
23+
md = MarkdownIt("commonmark").use(myst_block_plugin)
24+
tokens = md.parse("+++")
25+
assert tokens == [
26+
Token(
27+
type="myst_block_break",
28+
tag="hr",
29+
nesting=0,
30+
attrs=[["class", "myst-block"]],
31+
map=[0, 1],
32+
level=0,
33+
children=None,
34+
content="",
35+
markup="+++",
36+
info="",
37+
meta={},
38+
block=True,
39+
hidden=False,
40+
)
41+
]
42+
43+
tokens = md.parse("\n+ + + abc")
44+
assert tokens == [
45+
Token(
46+
type="myst_block_break",
47+
tag="hr",
48+
nesting=0,
49+
attrs=[["class", "myst-block"]],
50+
map=[1, 2],
51+
level=0,
52+
children=None,
53+
content="abc",
54+
markup="+++",
55+
info="",
56+
meta={},
57+
block=True,
58+
hidden=False,
59+
)
60+
]
61+
62+
63+
def test_comment_token():
64+
md = MarkdownIt("commonmark").use(myst_block_plugin)
65+
tokens = md.parse("\n\n% abc")
66+
assert tokens == [
67+
Token(
68+
type="myst_line_comment",
69+
tag="",
70+
nesting=0,
71+
attrs=[["class", "myst-line-comment"]],
72+
map=[2, 3],
73+
level=0,
74+
children=None,
75+
content="abc",
76+
markup="%",
77+
info="",
78+
meta={},
79+
block=True,
80+
hidden=False,
81+
)
82+
]

0 commit comments

Comments
 (0)