Skip to content

👌 Use str.removesuffix #348

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

Merged
merged 1 commit into from
Dec 18, 2024
Merged
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
13 changes: 1 addition & 12 deletions markdown_it/tree.py
Original file line number Diff line number Diff line change
@@ -162,7 +162,7 @@ def type(self) -> str:
if self.token:
return self.token.type
assert self.nester_tokens
return _removesuffix(self.nester_tokens.opening.type, "_open")
return self.nester_tokens.opening.type.removesuffix("_open")

@property
def next_sibling(self: _NodeType) -> _NodeType | None:
@@ -331,14 +331,3 @@ def hidden(self) -> bool:
"""If it's true, ignore this element when rendering.
Used for tight lists to hide paragraphs."""
return self._attribute_token().hidden


def _removesuffix(string: str, suffix: str) -> str:
"""Remove a suffix from a string.

Replace this with str.removesuffix() from stdlib when minimum Python
version is 3.9.
"""
if suffix and string.endswith(suffix):
return string[: -len(suffix)]
return string