diff --git a/MarkdownTOC.sublime-settings b/MarkdownTOC.sublime-settings index 596e94c..2e05f7d 100644 --- a/MarkdownTOC.sublime-settings +++ b/MarkdownTOC.sublime-settings @@ -14,14 +14,6 @@ "markdown_preview": "" }, "id_replacements": [ - { - "pattern": "[_*]{2}([^\\s])[_*]{2}", - "replacement": "\\1" - }, - { - "pattern": "[_*]([^\\s])[_*]", - "replacement": "\\1" - }, { "pattern": "\\s+", "replacement": "-" diff --git a/markdowntoc/id.py b/markdowntoc/id.py index 1c91587..948f8e6 100644 --- a/markdowntoc/id.py +++ b/markdowntoc/id.py @@ -41,7 +41,7 @@ def do_id_replacements(self, _str): _str = re.sub(r'`([^`]*)`', '[codeblock]', _str) # Treat '_' for italic and '_' as text - _str = re.sub(r'( |^)_([^_ ].*[^_ ])_( |$)', '\\1\\2\\3', _str) + _str = re.sub(r'( |^)([\*|_]{1,3})([^\*|_\s]+|[^\*|_\s].*[^\*|_\s])\2( |$)', '\\1\\3\\4', _str) # **[2] recover codeblocks for match in matches: diff --git a/tests/italic_in_heading.py b/tests/italic_in_heading.py index 8177e7a..d600cef 100644 --- a/tests/italic_in_heading.py +++ b/tests/italic_in_heading.py @@ -29,6 +29,8 @@ class TestItalic(TestBase): # `_should ignore underscores in codeblocks 2_ ` # this is ` _more complex_ ` exmaple # this_is_not_italic +# t_h_i_s__i_s__n_o_t__i_t_a_l_i_c +# _t_h_i_s__i_s__i_t_a_l_i_c_ """ def test_italic_in_inheading1(self): @@ -77,4 +79,12 @@ def test_italic_in_inheading11(self): def test_italic_in_inheading12(self): toc = self.init_update(self.bracket_text)['toc'] - self.assert_In('- [this_is_not_italic](#this_is_not_italic)', toc) \ No newline at end of file + self.assert_In('- [this_is_not_italic](#this_is_not_italic)', toc) + + def test_italic_in_inheading13(self): + toc = self.init_update(self.bracket_text)['toc'] + self.assert_In('- [t_h_i_s__i_s__n_o_t__i_t_a_l_i_c](#t_h_i_s__i_s__n_o_t__i_t_a_l_i_c)', toc) + + def test_italic_in_inheading14(self): + toc = self.init_update(self.bracket_text)['toc'] + self.assert_In('- [_t_h_i_s__i_s__i_t_a_l_i_c_](#t_h_i_s__i_s__i_t_a_l_i_c)', toc) \ No newline at end of file