Skip to content

Commit 774bb0a

Browse files
committed
Fix snippet line range with start of line 1
Fixes #2361
1 parent 45b53a7 commit 774bb0a

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

docs/src/markdown/about/changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 10.8.1
4+
5+
- **FIX**: Snippets: Fix snippet line range with a start of line 1.
6+
37
## 10.8
48

59
- **NEW**: Require Python Markdown 3.6+.

pymdownx/__meta__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,5 @@ def parse_version(ver, pre=False):
185185
return Version(major, minor, micro, release, pre, post, dev)
186186

187187

188-
__version_info__ = Version(10, 8, 0, "final")
188+
__version_info__ = Version(10, 8, 1, "final")
189189
__version__ = __version_info__._get_canonical()

pymdownx/snippets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def parse_snippets(self, lines, file_name=None, is_url=False):
292292
end = int(ending[1:])
293293
starting = m.group(2)
294294
if starting and len(starting) > 1:
295-
start = max(1, int(starting[1:]) - 1)
295+
start = max(0, int(starting[1:]) - 1)
296296
section_name = m.group(4)
297297
if section_name:
298298
section = section_name[1:]

tests/test_extensions/test_snippets.py

+27
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,33 @@ def test_start_line_inline(self):
209209
True
210210
)
211211

212+
def test_start_1_1(self):
213+
"""Test beginning of file, single line range."""
214+
215+
self.check_markdown(
216+
R'''
217+
---8<--- "lines.txt:1:1"
218+
''',
219+
'''
220+
<p>This is a multi-line</p>
221+
''',
222+
True
223+
)
224+
225+
def test_start_1_2(self):
226+
"""Test beginning of file span of multiple lines."""
227+
228+
self.check_markdown(
229+
R'''
230+
---8<--- "lines.txt:1:2"
231+
''',
232+
'''
233+
<p>This is a multi-line
234+
snippet.</p>
235+
''',
236+
True
237+
)
238+
212239
def test_end_line_inline(self):
213240
"""Test ending line with inline syntax."""
214241

0 commit comments

Comments
 (0)