Skip to content

Commit

Permalink
Fix snippet line range with start of line 1 (#2362)
Browse files Browse the repository at this point in the history
Fixes #2361
  • Loading branch information
facelessuser committed Apr 22, 2024
1 parent 45b53a7 commit 8ed2fcb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/src/markdown/about/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 10.8.1

- **FIX**: Snippets: Fix snippet line range with a start of line 1.

## 10.8

- **NEW**: Require Python Markdown 3.6+.
Expand Down
2 changes: 1 addition & 1 deletion pymdownx/__meta__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,5 @@ def parse_version(ver, pre=False):
return Version(major, minor, micro, release, pre, post, dev)


__version_info__ = Version(10, 8, 0, "final")
__version_info__ = Version(10, 8, 1, "final")
__version__ = __version_info__._get_canonical()
2 changes: 1 addition & 1 deletion pymdownx/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def parse_snippets(self, lines, file_name=None, is_url=False):
end = int(ending[1:])
starting = m.group(2)
if starting and len(starting) > 1:
start = max(1, int(starting[1:]) - 1)
start = max(0, int(starting[1:]) - 1)
section_name = m.group(4)
if section_name:
section = section_name[1:]
Expand Down
27 changes: 27 additions & 0 deletions tests/test_extensions/test_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,33 @@ def test_start_line_inline(self):
True
)

def test_start_1_1(self):
"""Test beginning of file, single line range."""

self.check_markdown(
R'''
---8<--- "lines.txt:1:1"
''',
'''
<p>This is a multi-line</p>
''',
True
)

def test_start_1_2(self):
"""Test beginning of file span of multiple lines."""

self.check_markdown(
R'''
---8<--- "lines.txt:1:2"
''',
'''
<p>This is a multi-line
snippet.</p>
''',
True
)

def test_end_line_inline(self):
"""Test ending line with inline syntax."""

Expand Down

0 comments on commit 8ed2fcb

Please sign in to comment.