Skip to content

Commit c8f82bc

Browse files
authored
👌 IMPROVE: Use re.sub() instead of re.subn()[0] (#58)
1 parent 4e1150e commit c8f82bc

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

markdown_it/common/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ def stripEscape(string):
172172

173173
# if HTML_ESCAPE_REPLACE_RE.search(string):
174174

175-
# string, _ = UNESCAPE_HTML_RE.subn("&", string)
176-
# string, _ = ESCAPE_AND_HTML.subn("&", string)
175+
# string = UNESCAPE_HTML_RE.sub("&", string)
176+
# string = ESCAPE_AND_HTML.sub("&", string)
177177
# for k, v in {"<": "&lt;", ">": "&gt;", '"': "&quot;"}.items():
178178
# string = string.replace(k, v)
179179

@@ -191,7 +191,7 @@ def escapeHtml(raw: str):
191191

192192

193193
def escapeRE(string: str) -> str:
194-
string, _ = REGEXP_ESCAPE_RE.subn("\\$&", string)
194+
string = REGEXP_ESCAPE_RE.sub("\\$&", string)
195195
return string
196196

197197

@@ -291,7 +291,7 @@ def normalizeReference(string: str) -> str:
291291
"""Helper to unify [reference labels]."""
292292
# Trim and collapse whitespace
293293
#
294-
string, _ = re.subn(r"\s+", " ", string.strip())
294+
string = re.sub(r"\s+", " ", string.strip())
295295

296296
# In node v10 'ẞ'.toLowerCase() === 'Ṿ', which is presumed to be a bug
297297
# fixed in v12 (couldn't find any details).

markdown_it/extensions/anchors/index.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,9 @@ def _anchor_func(state: StateCore):
7676
if level not in selected_levels:
7777
continue
7878
title = "".join(
79-
[
80-
child.content
81-
for child in state.tokens[idx + 1].children
82-
if child.type in ["text", "code_inline"]
83-
]
79+
child.content
80+
for child in state.tokens[idx + 1].children
81+
if child.type in ["text", "code_inline"]
8482
)
8583
slug = unique_slug(slug_func(title), slugs)
8684
token.attrSet("id", slug)
@@ -116,9 +114,7 @@ def _anchor_func(state: StateCore):
116114

117115

118116
def slugify(title: str):
119-
return re.subn(
120-
r"[^\w\u4e00-\u9fff\- ]", "", title.strip().lower().replace(" ", "-")
121-
)[0]
117+
return re.sub(r"[^\w\u4e00-\u9fff\- ]", "", title.strip().lower().replace(" ", "-"))
122118

123119

124120
def unique_slug(slug: str, slugs: set):

markdown_it/rules_block/table.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def table(state: StateBlock, startLine: int, endLine: int, silent: bool):
129129
return False
130130
if state.sCount[startLine] - state.blkIndent >= 4:
131131
return False
132-
columns = escapedSplit(enclosingPipesRe.subn("", lineText)[0])
132+
columns = escapedSplit(enclosingPipesRe.sub("", lineText))
133133

134134
# header row will define an amount of columns in the entire table,
135135
# and align row shouldn't be smaller than that (the rest of the rows can)
@@ -178,7 +178,7 @@ def table(state: StateBlock, startLine: int, endLine: int, silent: bool):
178178
break
179179
if state.sCount[nextLine] - state.blkIndent >= 4:
180180
break
181-
columns = escapedSplit(enclosingPipesRe.subn("", lineText)[0])
181+
columns = escapedSplit(enclosingPipesRe.sub("", lineText))
182182

183183
token = state.push("tr_open", "tr", 1)
184184
for i in range(columnCount):

markdown_it/rules_core/normalize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
def normalize(state: StateCore):
1313

1414
# Normalize newlines
15-
string, _ = NEWLINES_RE.subn("\n", state.src)
15+
string = NEWLINES_RE.sub("\n", state.src)
1616

1717
# Replace NULL characters
18-
string, _ = NULL_RE.subn("\uFFFD", string)
18+
string = NULL_RE.sub("\uFFFD", string)
1919

2020
state.src = string

0 commit comments

Comments
 (0)