diff --git a/Markdown/Markdown.sublime-syntax b/Markdown/Markdown.sublime-syntax
index 7933fe46b6..5ea0be5176 100644
--- a/Markdown/Markdown.sublime-syntax
+++ b/Markdown/Markdown.sublime-syntax
@@ -66,7 +66,9 @@ variables:
\s* # Optional whitespace
(\))
)
- skip_html_tags: '(?:<[^>]+>)'
+ skip_self_closing_html_tags: '(?:<(?:hr|br)\b[^>]*>)'
+ skip_html_tag_content: '(?:<[^>]+[^<]*[^>]+>)'
+ skip_html_tags: '(?:{{skip_self_closing_html_tags}}|{{skip_html_tag_content}})'
contexts:
main:
- match: |-
@@ -241,7 +243,11 @@ contexts:
)
| \*{3,} # not applicable
| [ \t]\*+ # Match whitespace followed by the style closer because it doesn't close the style
- | (?!\*\*). # Everything else besides style closer
+ | (?!
+ {{skip_html_tags}} # emulate possessive quantifers by repeating patterns
+ | {{backticks}}
+ | {{escape}}
+ | \*\*). # Everything else besides style closer
)+
\*\* # Close
)
@@ -262,7 +268,7 @@ contexts:
- include: italic
- match: |-
(?x)
- (\b__)(?=\S)(?!_) # Open
+ (\b__)(?=\S)(?!_) # Open
(?=
(?:
{{skip_html_tags}} # HTML tags
@@ -278,7 +284,11 @@ contexts:
)
| _{3,} # not applicable
| [ \t]_+ # Match whitespace followed by the style closer because it doesn't close the style
- | (?!__). # Everything else besides style closer
+ | (?!
+ {{skip_html_tags}} # emulate possessive quantifers by repeating patterns
+ | {{backticks}}
+ | {{escape}}
+ | __). # Everything else besides style closer
)+
__ # Close
)
@@ -426,7 +436,11 @@ contexts:
)
| \*{2,} # Must be bold opener or closer or not applicable
| [ \t]\*+ # Match whitespace followed by the style closer because it doesn't close the style
- | (?!\*). # Everything else besides style closer
+ | (?!
+ {{skip_html_tags}} # emulate possessive quantifers by repeating patterns
+ | {{backticks}}
+ | {{escape}}
+ | \*). # Everything else besides style closer
)+
\* # Close
)
@@ -447,7 +461,7 @@ contexts:
- include: bold
- match: |-
(?x)
- (\b_)(?=\S)(?!_) # Open
+ (\b_)(?=\S)(?!_) # Open
(?=
(?:
{{skip_html_tags}} # HTML tags
@@ -463,7 +477,11 @@ contexts:
)
| _{2,} # Must be bold opener or closer or not applicable
| [ \t]_+ # Match whitespace followed by the style closer because it doesn't close the style
- | (?!_). # Everything else besides style closer
+ | (?!
+ {{skip_html_tags}} # emulate possessive quantifers by repeating patterns
+ | {{backticks}}
+ | {{escape}}
+ | _). # Everything else besides style closer
)+
_ # Close
)
@@ -475,7 +493,6 @@ contexts:
(?x)
[ \t]*_{3,} # if there are more than 3 its not applicable to be bold or italic
| [ \t]+_(?!_) # whitespace followed by 1 is also not applicable (but whitespace followed by 2 could be bold punctuation)
-
- match: (\1)(?!\1)
captures:
1: punctuation.definition.italic.end.markdown
diff --git a/Markdown/syntax_test_markdown.md b/Markdown/syntax_test_markdown.md
index 0c49c818b6..4cf978becd 100644
--- a/Markdown/syntax_test_markdown.md
+++ b/Markdown/syntax_test_markdown.md
@@ -465,3 +465,42 @@ more _tests here_
| ^ punctuation.definition.italic.begin
| ^ - punctuation.definition
| ^ punctuation.definition.italic.end
+_more `tests_` here_
+| <- punctuation.definition.italic.begin
+| ^^^^^^^^ markup.raw.inline
+| ^ punctuation.definition.italic.end
+__more `tests__` here__
+| <- punctuation.definition.bold.begin
+| ^^^^^^^^^ markup.raw.inline
+| ^^ punctuation.definition.bold.end
+_test text_ not formatted
+| <- - punctuation
+| ^ - punctuation
+__test text__ not formatted
+| <- - punctuation
+| ^^ - punctuation
+*test text* not formatted
+| <- - punctuation
+| ^ - punctuation
+**test text** not formatted
+| <- - punctuation
+| ^^ - punctuation
+_test text **formatted**_
+| <- punctuation
+| ^^ punctuation
+| ^^ punctuation
+| ^ punctuation
+*test text __formatted__*
+| <- punctuation
+| ^^ punctuation
+| ^^ punctuation
+| ^ punctuation
+*test text __formatted__* **more** _text_
+| <- punctuation
+| ^^ punctuation
+| ^^ punctuation
+| ^ punctuation
+| ^^ punctuation
+| ^^ punctuation
+| ^ punctuation
+| ^ punctuation