summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfacelessuser <faceless.shop@gmail.com>2020-06-20 10:00:21 -0600
committerWaylan Limberg <waylan.limberg@icloud.com>2020-06-22 10:35:15 -0400
commitdbb9b3d766e847f1909fa0c92c6b997f0e7c868d (patch)
tree702fc9fa98480f7166d500e53fba7568d64c00d1
parenta06659b62209de98cbc23715addb2b768a245788 (diff)
downloadpython-markdown-dbb9b3d766e847f1909fa0c92c6b997f0e7c868d.tar.gz
Fix issues with complex emphasis
Resolves issue that can occur with complex emphasis combinations. Fixes #979
-rw-r--r--docs/change_log/release-3.3.md16
-rw-r--r--markdown/extensions/legacy_em.py2
-rw-r--r--markdown/inlinepatterns.py4
-rw-r--r--tests/test_syntax/extensions/test_legacy_em.py14
-rw-r--r--tests/test_syntax/inline/test_emphasis.py14
5 files changed, 47 insertions, 3 deletions
diff --git a/docs/change_log/release-3.3.md b/docs/change_log/release-3.3.md
new file mode 100644
index 0000000..bc7cd40
--- /dev/null
+++ b/docs/change_log/release-3.3.md
@@ -0,0 +1,16 @@
+title: Release Notes for v3.3
+
+# Python-Markdown 3.3 Release Notes
+
+Python-Markdown version 3.3 supports Python versions 3.5, 3.6, 3.7, 3.8, and
+PyPy3.
+
+## Backwards-incompatible changes
+
+## New features
+
+## Bug fixes
+
+The following bug fixes are included in the 3.3 release:
+
+* Fix issues with complex emphasis (#979).
diff --git a/markdown/extensions/legacy_em.py b/markdown/extensions/legacy_em.py
index c3d7b54..7fddb77 100644
--- a/markdown/extensions/legacy_em.py
+++ b/markdown/extensions/legacy_em.py
@@ -21,7 +21,7 @@ EMPHASIS_RE = r'(_)([^_]+)\1'
STRONG_RE = r'(_{2})(.+?)\1'
# __strong_em___
-STRONG_EM_RE = r'(_)\1(?!\1)(.+?)\1(?!\1)(.+?)\1{3}'
+STRONG_EM_RE = r'(_)\1(?!\1)([^_]+?)\1(?!\1)(.+?)\1{3}'
class LegacyUnderscoreProcessor(UnderscoreProcessor):
diff --git a/markdown/inlinepatterns.py b/markdown/inlinepatterns.py
index ad95519..0655047 100644
--- a/markdown/inlinepatterns.py
+++ b/markdown/inlinepatterns.py
@@ -135,8 +135,8 @@ STRONG_EM_RE = r'(\*)\1{2}(.+?)\1{2}(.*?)\1'
# ___strong__em_
STRONG_EM2_RE = r'(_)\1{2}(.+?)\1{2}(.*?)\1'
-# __strong_em___
-STRONG_EM3_RE = r'(\*)\1(?!\1)(.+?)\1(?!\1)(.+?)\1{3}'
+# **strong*em***
+STRONG_EM3_RE = r'(\*)\1(?!\1)([^*]+?)\1(?!\1)(.+?)\1{3}'
# [text](url) or [text](<url>) or [text](url "title")
LINK_RE = NOIMG + r'\['
diff --git a/tests/test_syntax/extensions/test_legacy_em.py b/tests/test_syntax/extensions/test_legacy_em.py
index efad43d..c5daf1c 100644
--- a/tests/test_syntax/extensions/test_legacy_em.py
+++ b/tests/test_syntax/extensions/test_legacy_em.py
@@ -50,3 +50,17 @@ class TestLegacyEm(TestCase):
'<p>This is text <strong>bold<em>italic bold</em></strong> with more text</p>',
extensions=['legacy_em']
)
+
+ def test_complex_multple_underscore_type(self):
+
+ self.assertMarkdownRenders(
+ 'traced ___along___ bla __blocked__ if other ___or___',
+ '<p>traced <strong><em>along</em></strong> bla <strong>blocked</strong> if other <strong><em>or</em></strong></p>' # noqa: E501
+ )
+
+ def test_complex_multple_underscore_type_variant2(self):
+
+ self.assertMarkdownRenders(
+ 'on the __1-4 row__ of the AP Combat Table ___and___ receive',
+ '<p>on the <strong>1-4 row</strong> of the AP Combat Table <strong><em>and</em></strong> receive</p>'
+ )
diff --git a/tests/test_syntax/inline/test_emphasis.py b/tests/test_syntax/inline/test_emphasis.py
index b4f1d0d..1e7fafa 100644
--- a/tests/test_syntax/inline/test_emphasis.py
+++ b/tests/test_syntax/inline/test_emphasis.py
@@ -114,3 +114,17 @@ class TestNotEmphasis(TestCase):
'This text is **bold *italic* *italic* bold**',
'<p>This text is <strong>bold <em>italic</em> <em>italic</em> bold</strong></p>'
)
+
+ def test_complex_multple_emphasis_type(self):
+
+ self.assertMarkdownRenders(
+ 'traced ***along*** bla **blocked** if other ***or***',
+ '<p>traced <strong><em>along</em></strong> bla <strong>blocked</strong> if other <strong><em>or</em></strong></p>' # noqa: E501
+ )
+
+ def test_complex_multple_emphasis_type_variant2(self):
+
+ self.assertMarkdownRenders(
+ 'on the **1-4 row** of the AP Combat Table ***and*** receive',
+ '<p>on the <strong>1-4 row</strong> of the AP Combat Table <strong><em>and</em></strong> receive</p>'
+ )