Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 201ec81

Browse files
committed
Merge pull request trentm#157 from trentm/nicholasserra-hr-length
Horizontal rules need to be at least 3 chars.
2 parents 35cd09f + 1ec0ba6 commit 201ec81

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

lib/markdown2.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -776,12 +776,7 @@ def _strip_footnote_definitions(self, text):
776776
re.X | re.M)
777777
return footnote_def_re.sub(self._extract_footnote_def_sub, text)
778778

779-
780-
_hr_data = [
781-
('*', re.compile(r"^[ ]{0,3}\*(.*?)$", re.M)),
782-
('-', re.compile(r"^[ ]{0,3}\-(.*?)$", re.M)),
783-
('_', re.compile(r"^[ ]{0,3}\_(.*?)$", re.M)),
784-
]
779+
_hr_re = re.compile(r'^[ ]{0,3}([-_*][ ]{0,2}){3,}$', re.M)
785780

786781
def _run_block_gamut(self, text):
787782
# These are all the transformations that form block-level
@@ -798,13 +793,7 @@ def _run_block_gamut(self, text):
798793
# Markdown.pl 1.0.1's hr regexes limit the number of spaces between the
799794
# hr chars to one or two. We'll reproduce that limit here.
800795
hr = "\n<hr"+self.empty_element_suffix+"\n"
801-
for ch, regex in self._hr_data:
802-
if ch in text:
803-
for m in reversed(list(regex.finditer(text))):
804-
tail = m.group(1).rstrip()
805-
if not tail.strip(ch + ' ') and tail.count(" ") == 0:
806-
start, end = m.span()
807-
text = text[:start] + hr + text[end:]
796+
text = re.sub(self._hr_re, hr, text)
808797

809798
text = self._do_lists(text)
810799

test/tm-cases/hr_length.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<h1>horizontal rules need to be at least 3 characters</h1>
2+
3+
<p>-</p>
4+
5+
<p>*</p>
6+
7+
<p>_</p>
8+
9+
<p>--</p>
10+
11+
<p>**</p>
12+
13+
<p>__</p>
14+
15+
<hr />
16+
17+
<hr />
18+
19+
<hr />

test/tm-cases/hr_length.text

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# horizontal rules need to be at least 3 characters
2+
3+
-
4+
5+
*
6+
7+
_
8+
9+
--
10+
11+
**
12+
13+
__
14+
15+
---
16+
17+
***
18+
19+
___

0 commit comments

Comments
 (0)