Skip to content
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

Fix snippet line range with start of line 1 #2362

Merged
merged 1 commit into from
Apr 22, 2024
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
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