Skip to content

Commit 0ff53a0

Browse files
committed
Fix line position record of front matter
1 parent 9e8d9ea commit 0ff53a0

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
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.1"
4+
__version__ = "0.4.2"

markdown_it/extensions/front_matter/index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def frontMatter(state: StateBlock, startLine: int, endLine: int, silent: bool):
8181
continue
8282

8383
pos = start + 1
84-
while pos <= maximum:
84+
while pos < maximum:
8585
if marker_str[(pos - start) % marker_len] != state.src[pos]:
8686
break
8787
pos += 1
@@ -115,12 +115,12 @@ def frontMatter(state: StateBlock, startLine: int, endLine: int, silent: bool):
115115
state.bMarks[startLine + 1] : state.eMarks[nextLine - 1]
116116
]
117117
token.block = True
118-
token.map = [startLine, pos]
119118
token.meta = state.src[start_content : start - 1]
120119

121120
state.parentType = old_parent
122121
state.lineMax = old_line_max
123122
state.line = nextLine + (1 if auto_closed else 0)
123+
token.map = [startLine, state.line - 1]
124124

125125
return True
126126

tests/test_front_matter/test_fixtures.py

Lines changed: 24 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.front_matter import front_matter_plugin
89

@@ -16,3 +17,26 @@ 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_token():
23+
md = MarkdownIt("commonmark").use(front_matter_plugin)
24+
tokens = md.parse("---\na: 1\n---")
25+
# print(tokens)
26+
assert tokens == [
27+
Token(
28+
type="front_matter",
29+
tag="",
30+
nesting=0,
31+
attrs=None,
32+
map=[0, 2],
33+
level=0,
34+
children=None,
35+
content="a: 1",
36+
markup="---",
37+
info="",
38+
meta="a: 1",
39+
block=True,
40+
hidden=True,
41+
)
42+
]

0 commit comments

Comments
 (0)