Skip to content

Commit

Permalink
Fix italic and bold syntax problem #142
Browse files Browse the repository at this point in the history
  • Loading branch information
naokazuterada committed Jan 19, 2020
1 parent 0342bfc commit 0d305a4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
8 changes: 0 additions & 8 deletions MarkdownTOC.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@
"markdown_preview": ""
},
"id_replacements": [
{
"pattern": "[_*]{2}([^\\s])[_*]{2}",
"replacement": "\\1"
},
{
"pattern": "[_*]([^\\s])[_*]",
"replacement": "\\1"
},
{
"pattern": "\\s+",
"replacement": "-"
Expand Down
2 changes: 1 addition & 1 deletion markdowntoc/id.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 11 additions & 1 deletion tests/italic_in_heading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
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)

0 comments on commit 0d305a4

Please sign in to comment.