Skip to content

Commit 63abe4b

Browse files
committed
chore: use ruff check and format
1 parent e6c1b18 commit 63abe4b

9 files changed

Lines changed: 14 additions & 37 deletions

File tree

‎src/mistune/block_parser.py‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,7 @@ def parse_block_quote(self, m: Match[str], state: BlockState) -> int:
372372
# At the nesting limit, stop descending into any further container
373373
# blocks. Trimming only "block_quote" still allowed block quotes and
374374
# lists to recurse into each other without bound (RecursionError).
375-
rules = [
376-
rule
377-
for rule in self.block_quote_rules
378-
if rule not in ("block_quote", "list")
379-
]
375+
rules = [rule for rule in self.block_quote_rules if rule not in ("block_quote", "list")]
380376
else:
381377
rules = self.block_quote_rules
382378

‎src/mistune/directives/_rst.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ def parse_title(m: Match[str]) -> str:
3131

3232
@staticmethod
3333
def parse_content(m: Match[str]) -> str:
34-
full_content = m.group(0)
3534
text = m.group("text")
36-
pretext = full_content[: -len(text)]
3735
leading = len(m.group(1)) + 2
3836
return "\n".join(line[leading:] for line in text.splitlines()) + "\n"
3937

‎src/mistune/helpers.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def parse_link_text(src: str, pos: int) -> Union[Tuple[str, int], Tuple[None, in
115115
level += 1
116116

117117
if found:
118-
text = src[start_pos: pos - 1]
118+
text = src[start_pos : pos - 1]
119119
return text, pos
120120
return None, pos # FIX: return pos instead of None
121121

‎src/mistune/list_parser.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ def parse_list(block: "BlockParser", m: Match[str], state: "BlockState") -> int:
8888
# At the nesting limit, stop descending into any further container
8989
# blocks. Trimming only "list" still allowed lists and block quotes to
9090
# recurse into each other without bound (RecursionError).
91-
rules = [
92-
rule for rule in block.list_rules if rule not in ("list", "block_quote")
93-
]
91+
rules = [rule for rule in block.list_rules if rule not in ("list", "block_quote")]
9492
else:
9593
rules = block.list_rules
9694

‎src/mistune/plugins/formatting.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,7 @@ def _find_end_marker(src: str, pos: int, marker: str) -> Optional[int]:
8585
if end > pos:
8686
prev = src[end - 1]
8787
escaped_marker_before = (
88-
prev == c
89-
and end >= pos + 2
90-
and src[end - 2] == "\\"
91-
and not _has_odd_backslashes(src, end - 2)
88+
prev == c and end >= pos + 2 and src[end - 2] == "\\" and not _has_odd_backslashes(src, end - 2)
9289
)
9390
if (not prev.isspace() and prev != c) or escaped_marker_before:
9491
return marker_end

‎src/mistune/plugins/table.py‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@
2020
__all__ = ["table", "table_in_quote", "table_in_list"]
2121

2222

23-
TABLE_PATTERN = (
24-
r"^ {0,3}\|[^\n]*\|[ \t]*(?:\n|$)"
25-
)
26-
NP_TABLE_PATTERN = (
27-
r"^ {0,3}\S[^\n]*\|[^\n]*(?:\n|$)"
28-
)
23+
TABLE_PATTERN = r"^ {0,3}\|[^\n]*\|[ \t]*(?:\n|$)"
24+
NP_TABLE_PATTERN = r"^ {0,3}\S[^\n]*\|[^\n]*(?:\n|$)"
2925

3026
ALIGN_CENTER = re.compile(r"^ *:-+: *$")
3127
ALIGN_LEFT = re.compile(r"^ *:-+ *$")
@@ -154,7 +150,7 @@ def _parse_invalid_pipe_table(state: "BlockState", pos: int) -> int:
154150
if _strip_pipe_table_row(line) is None:
155151
break
156152
pos += len(line)
157-
state.add_paragraph(state.src[state.cursor:pos])
153+
state.add_paragraph(state.src[state.cursor : pos])
158154
return pos
159155

160156

‎src/mistune/renderers/markdown.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ def table(self, token: Dict[str, Any], state: BlockState) -> str:
162162

163163
def table_head(self, token: Dict[str, Any], state: BlockState) -> str:
164164
cells = token.get("children", [])
165-
return _render_table_row(self, cells, state) + "\n" + _render_table_delimiter([_table_cell_align(c) for c in cells])
165+
return (
166+
_render_table_row(self, cells, state)
167+
+ "\n"
168+
+ _render_table_delimiter([_table_cell_align(c) for c in cells])
169+
)
166170

167171
def table_body(self, token: Dict[str, Any], state: BlockState) -> str:
168172
return "\n".join(self.render_token(row, state).rstrip("\n") for row in token.get("children", []))

‎tests/test_hooks.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
from mistune import create_markdown
32
from mistune.toc import add_toc_hook, render_toc_ul
43
from tests import BaseTestCase

‎tests/test_security_image.py‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@
77
class TestImageDirectiveSecurity(TestCase):
88
def test_image_directive_rejects_css_dimension_injection(self):
99
md = create_markdown(escape=True, plugins=[FencedDirective([Image()])])
10-
html = md(
11-
"```{image} x.jpg\n"
12-
":width: 100vw;height:100vh;position:fixed;top:0\n"
13-
":height: 50%\n"
14-
":alt: <alt>\n"
15-
"```\n"
16-
)
10+
html = md("```{image} x.jpg\n:width: 100vw;height:100vh;position:fixed;top:0\n:height: 50%\n:alt: <alt>\n```\n")
1711

1812
self.assertIn('alt="&lt;alt&gt;"', html)
1913
self.assertIn('style="height:50%;"', html)
@@ -22,12 +16,7 @@ def test_image_directive_rejects_css_dimension_injection(self):
2216
def test_figure_directive_escapes_class_and_rejects_figwidth_css_injection(self):
2317
md = create_markdown(escape=True, plugins=[FencedDirective([Figure()])])
2418
html = md(
25-
"```{figure} x.jpg\n"
26-
':figclass: evil" onclick="alert(1)\n'
27-
":figwidth: 10px;position:fixed\n"
28-
"\n"
29-
"caption\n"
30-
"```\n"
19+
'```{figure} x.jpg\n:figclass: evil" onclick="alert(1)\n:figwidth: 10px;position:fixed\n\ncaption\n```\n'
3120
)
3221

3322
self.assertIn('class="figure evil&quot; onclick=&quot;alert(1)"', html)

0 commit comments

Comments
 (0)