Skip to content

Commit 24977fd

Browse files
authored
rename regex pattern variables (#195)
Signed-off-by: chrispy <[email protected]>
1 parent c7329ac commit 24977fd

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

Diff for: markdownify/__init__.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
import six
55

66

7-
convert_heading_re = re.compile(r'convert_h(\d+)')
8-
line_with_content_re = re.compile(r'^(.*)', flags=re.MULTILINE)
9-
whitespace_re = re.compile(r'[\t ]+')
10-
all_whitespace_re = re.compile(r'[\t \r\n]+')
11-
newline_whitespace_re = re.compile(r'[\t \r\n]*[\r\n][\t \r\n]*')
12-
html_heading_re = re.compile(r'h[1-6]')
7+
re_convert_heading = re.compile(r'convert_h(\d+)')
8+
re_line_with_content = re.compile(r'^(.*)', flags=re.MULTILINE)
9+
re_whitespace = re.compile(r'[\t ]+')
10+
re_all_whitespace = re.compile(r'[\t \r\n]+')
11+
re_newline_whitespace = re.compile(r'[\t \r\n]*[\r\n][\t \r\n]*')
12+
re_html_heading = re.compile(r'h[1-6]')
1313

1414
# extract (leading_nl, content, trailing_nl) from a string
1515
# (functionally equivalent to r'^(\n*)(.*?)(\n*)$', but greedy is faster than reluctant here)
16-
extract_newlines_re = re.compile(r'^(\n*)((?:.*[^\n])?)(\n*)$', flags=re.DOTALL)
16+
re_extract_newlines = re.compile(r'^(\n*)((?:.*[^\n])?)(\n*)$', flags=re.DOTALL)
1717

1818

1919
# Heading styles
@@ -80,7 +80,7 @@ def should_remove_whitespace_inside(el):
8080
"""Return to remove whitespace immediately inside a block-level element."""
8181
if not el or not el.name:
8282
return False
83-
if html_heading_re.match(el.name) is not None:
83+
if re_html_heading.match(el.name) is not None:
8484
return True
8585
return el.name in ('p', 'blockquote',
8686
'article', 'div', 'section',
@@ -221,7 +221,7 @@ def _can_ignore(el):
221221

222222
# if this tag is a heading or table cell, add an '_inline' parent pseudo-tag
223223
if (
224-
html_heading_re.match(node.name) is not None # headings
224+
re_html_heading.match(node.name) is not None # headings
225225
or node.name in {'td', 'th'} # table cells
226226
):
227227
parent_tags_for_children.add('_inline')
@@ -248,7 +248,7 @@ def _can_ignore(el):
248248
updated_child_strings = [''] # so the first lookback works
249249
for child_string in child_strings:
250250
# Separate the leading/trailing newlines from the content.
251-
leading_nl, content, trailing_nl = extract_newlines_re.match(child_string).groups()
251+
leading_nl, content, trailing_nl = re_extract_newlines.match(child_string).groups()
252252

253253
# If the last child had trailing newlines and this child has leading newlines,
254254
# use the larger newline count, limited to 2.
@@ -298,10 +298,10 @@ def process_text(self, el, parent_tags=None):
298298
# normalize whitespace if we're not inside a preformatted element
299299
if 'pre' not in parent_tags:
300300
if self.options['wrap']:
301-
text = all_whitespace_re.sub(' ', text)
301+
text = re_all_whitespace.sub(' ', text)
302302
else:
303-
text = newline_whitespace_re.sub('\n', text)
304-
text = whitespace_re.sub(' ', text)
303+
text = re_newline_whitespace.sub('\n', text)
304+
text = re_whitespace.sub(' ', text)
305305

306306
# escape special characters if we're not inside a preformatted or code element
307307
if '_noformat' not in parent_tags:
@@ -323,7 +323,7 @@ def process_text(self, el, parent_tags=None):
323323

324324
def __getattr__(self, attr):
325325
# Handle headings
326-
m = convert_heading_re.match(attr)
326+
m = re_convert_heading.match(attr)
327327
if m:
328328
n = int(m.group(1))
329329

@@ -409,7 +409,7 @@ def convert_blockquote(self, el, text, parent_tags):
409409
def _indent_for_blockquote(match):
410410
line_content = match.group(1)
411411
return '> ' + line_content if line_content else '>'
412-
text = line_with_content_re.sub(_indent_for_blockquote, text)
412+
text = re_line_with_content.sub(_indent_for_blockquote, text)
413413

414414
return '\n' + text + '\n\n'
415415

@@ -455,7 +455,7 @@ def convert_dd(self, el, text, parent_tags):
455455
def _indent_for_dd(match):
456456
line_content = match.group(1)
457457
return ' ' + line_content if line_content else ''
458-
text = line_with_content_re.sub(_indent_for_dd, text)
458+
text = re_line_with_content.sub(_indent_for_dd, text)
459459

460460
# insert definition marker into first-line indent whitespace
461461
text = ':' + text[1:]
@@ -465,7 +465,7 @@ def _indent_for_dd(match):
465465
def convert_dt(self, el, text, parent_tags):
466466
# remove newlines from term text
467467
text = (text or '').strip()
468-
text = all_whitespace_re.sub(' ', text)
468+
text = re_all_whitespace.sub(' ', text)
469469
if '_inline' in parent_tags:
470470
return ' ' + text + ' '
471471
if not text:
@@ -489,7 +489,7 @@ def _convert_hn(self, n, el, text, parent_tags):
489489
if style == UNDERLINED and n <= 2:
490490
line = '=' if n == 1 else '-'
491491
return self.underline(text, line)
492-
text = all_whitespace_re.sub(' ', text)
492+
text = re_all_whitespace.sub(' ', text)
493493
hashes = '#' * n
494494
if style == ATX_CLOSED:
495495
return '\n\n%s %s %s\n\n' % (hashes, text, hashes)
@@ -558,7 +558,7 @@ def convert_li(self, el, text, parent_tags):
558558
def _indent_for_li(match):
559559
line_content = match.group(1)
560560
return bullet_indent + line_content if line_content else ''
561-
text = line_with_content_re.sub(_indent_for_li, text)
561+
text = re_line_with_content.sub(_indent_for_li, text)
562562

563563
# insert bullet into first-line indent whitespace
564564
text = bullet + text[bullet_width:]

0 commit comments

Comments
 (0)