Skip to content

Commit 172bb31

Browse files
committed
Syntax: Fix image tags
1 parent f1e0581 commit 172bb31

2 files changed

Lines changed: 174 additions & 26 deletions

File tree

syntaxes/Markdown.sublime-syntax

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,55 +38,58 @@ variables:
3838
3939
backticks: |-
4040
(?x:
41-
(`{4})(?![\s`])(?:[^`]+(?=`)|(?!`{4})`+(?!`))+(`{4})(?!`) # 4 backticks, followed by at least one non whitespace, non backtick character, followed by (less than 4 backticks, or at least one non backtick character) at least once, followed by exactly 4 backticks
42-
| (`{3})(?![\s`])(?:[^`]+(?=`)|(?!`{3})`+(?!`))+(`{3})(?!`) # 3 backticks, followed by at least one non whitespace, non backtick character, followed by (less than 3 backticks, or at least one non backtick character) at least once, followed by exactly 3 backticks
43-
| (`{2})(?![\s`])(?:[^`]+(?=`)|(?!`{2})`+(?!`))+(`{2})(?!`) # 2 backticks, followed by at least one non whitespace, non backtick character, followed by (less than 2 backticks, or at least one non backtick character) at least once, followed by exactly 2 backticks
44-
| (`{1})(?![\s`])(?:[^`]+(?=`)|(?!`{1})`+(?!`))+(`{1})(?!`) # 1 backtick, followed by at least one non whitespace, non backtick character, followed by ( at least one non backtick character) at least once, followed by exactly 1 backtick
41+
(`{4})[^`](?:[^`]|(?!`{4})`+[^`])*(`{4})(?!`) # 4 backticks, followed by at least one non backtick character, followed by (less than 4 backticks, or at least one non backtick character) at least once, followed by exactly 4 backticks
42+
| (`{3})[^`](?:[^`]|(?!`{3})`+[^`])*(`{3})(?!`) # 3 backticks, followed by at least one non backtick character, followed by (less than 3 backticks, or at least one non backtick character) at least once, followed by exactly 3 backticks
43+
| (`{2})[^`](?:[^`]|(?!`{2})`+[^`])*(`{2})(?!`) # 2 backticks, followed by at least one non backtick character, followed by (less than 2 backticks, or at least one non backtick character) at least once, followed by exactly 2 backticks
44+
| (`{1})[^`](?:[^`]|(?!`{1})`+[^`])*(`{1})(?!`) # 1 backtick, followed by at least one non backtick character, followed by ( at least one non backtick character) at least once, followed by exactly 1 backtick
4545
)
4646
escapes: \\[-+*/!"#$%&'(),.:;<=>?@\[\\\]^_`{|}~]
4747

4848
balance_square_brackets: |-
4949
(?x:
5050
(?:
51-
(?:{{escapes}})+ # escape characters
52-
| [^\[\]`\\]+(?=[\[\]`\\]|$) # anything that isn't a square bracket or a backtick or the start of an escape character
51+
\\. # maybe escaped character (be lazy)
52+
| [^\[\]`] # anything that isn't a square bracket or backtick
5353
| {{backticks}} # inline code
54-
| \[(?: # nested square brackets (one level deep)
55-
[^\[\]`]+(?=[\[\]`]) # anything that isn't a square bracket or a backtick
56-
{{backticks}}? # balanced backticks
57-
)*\] # closing square bracket
54+
| \[ (?: # nested square brackets (one level deep)
55+
\\. # maybe escaped character (be lazy)
56+
| [^\[\]`] # anything that isn't a square bracket or backtick
57+
| {{backticks}} # inline code
58+
)* \] # closing square bracket
5859
)+
5960
)
6061
balance_square_brackets_and_emphasis: |-
6162
(?x:
6263
(?:
63-
(?:{{escapes}})+ # escape characters
64-
| [^\[\]`\\_*]+(?=[\[\]`\\_*]|$) # anything that isn't a square bracket, a backtick, the start of an escape character, or an emphasis character
64+
\\. # maybe escaped character (be lazy)
65+
| [^\[\]`_*] # anything that isn't a square bracket, backtick or emphasis
6566
| {{backticks}} # inline code
66-
| \[(?: # nested square brackets (one level deep)
67-
[^\[\]`]+(?=[\[\]`]) # anything that isn't a square bracket or a backtick
68-
{{backticks}}? # balanced backticks
69-
)*\] # closing square bracket
67+
| \[ (?: # nested square brackets (one level deep)
68+
\\. # maybe escaped character (be lazy)
69+
| [^\[\]`_*] # anything that isn't a square bracket, backtick or emphasis
70+
| {{backticks}} # inline code
71+
)* \] # closing square bracket
7072
)+ # at least one character
7173
)
7274
balance_square_brackets_pipes_and_emphasis: |-
7375
(?x:
7476
(?:
75-
(?:{{escapes}})+ # escape characters
76-
| [^\[\]`\\_*|]+(?=[\[\]`\\_*|]|$) # anything that isn't a square bracket, a backtick, the start of an escape character, or an emphasis character
77+
\\. # maybe escaped character (be lazy)
78+
| [^\[\]`_*|] # anything that isn't a square bracket, backtick or emphasis or table cell separator
7779
| {{backticks}} # inline code
78-
| \[(?: # nested square brackets (one level deep)
79-
[^\[\]`]+(?=[\[\]`]) # anything that isn't a square bracket or a backtick
80-
{{backticks}}? # balanced backticks
81-
)*\] # closing square bracket
80+
| \[ (?: # nested square brackets (one level deep)
81+
\\. # maybe escaped character (be lazy)
82+
| [^\[\]`_*|] # anything that isn't a square bracket, backtick or emphasis or table cell separator
83+
| {{backticks}} # inline code
84+
)* \] # closing square bracket
8285
)+ # at least one character
8386
)
8487
balanced_emphasis: |-
8588
(?x:
86-
\* (?!\*){{balance_square_brackets_and_emphasis}}+\* (?!\*)
87-
| \*\* {{balance_square_brackets_and_emphasis}}+\*\*
88-
| _ (?!_) {{balance_square_brackets_and_emphasis}}+_ (?!_)
89-
| __ {{balance_square_brackets_and_emphasis}}+__
89+
\* (?!\*){{balance_square_brackets_and_emphasis}}\* (?!\*)
90+
| \*\* {{balance_square_brackets_and_emphasis}}\*\*
91+
| _ (?!_) {{balance_square_brackets_and_emphasis}}_ (?!_)
92+
| __ {{balance_square_brackets_and_emphasis}}__
9093
)
9194
9295
table_cell: |-

tests/syntax_test_markdown.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5718,6 +5718,25 @@ blah*
57185718
| ^ punctuation.definition.string.begin.markdown
57195719
| ^ punctuation.definition.string.end.markdown
57205720
| ^ punctuation.definition.metadata.end.markdown
5721+
5722+
Complex ![image $\ce{H2O}$.](./img/image6.png){#fig:image6 height=12.09cm }
5723+
| ^^^^^^^^^^^^^^^^^^^^ meta.image.inline.description.markdown
5724+
| ^^ punctuation.definition.image.begin.markdown
5725+
| ^^^^^^^^^^ markup.math.inline.markdown text.tex.latex.embedded.markdown meta.environment.math.block.dollar.latex
5726+
| ^ punctuation.definition.image.end.markdown
5727+
| ^^^^^^^^^^^^^^^^^^ meta.image.inline.metadata.markdown
5728+
| ^ punctuation.definition.metadata.begin.markdown
5729+
| ^^^^^^^^^^^^^^^^ markup.underline.link.image.markdown
5730+
| ^ punctuation.definition.metadata.end.markdown
5731+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.image.inline.attributes.markdown
5732+
| ^ punctuation.definition.attributes.begin.markdown
5733+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute-with-value.markdown
5734+
| ^^^^^^^^^^^ entity.other.attribute-name.markdown
5735+
| ^^^^^^ entity.other.attribute-name.markdown
5736+
| ^ punctuation.separator.key-value.markdown
5737+
| ^^^^^^^ string.unquoted.markdown
5738+
| ^ punctuation.definition.attributes.end.markdown
5739+
57215740

57225741

57235742
# TEST: CODE SPANS ############################################################
@@ -7057,6 +7076,27 @@ A ==![highlight](https://image-url)==
70577076
A ==[![highlight](image-url)](link-url)==
70587077
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.paragraph.markdown markup.highlight.markdown
70597078
7079+
A ==![image $\ce{H2O}$.](./img/image6.png){#fig:image6 height=12.09cm }==
7080+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.highlight.markdown
7081+
| ^^ punctuation.definition.highlight.begin.markdown
7082+
| ^^^^^^^^^^^^^^^^^^^^ meta.image.inline.description.markdown
7083+
| ^^ punctuation.definition.image.begin.markdown
7084+
| ^^^^^^^^^^ markup.math.inline.markdown text.tex.latex.embedded.markdown meta.environment.math.block.dollar.latex
7085+
| ^ punctuation.definition.image.end.markdown
7086+
| ^^^^^^^^^^^^^^^^^^ meta.image.inline.metadata.markdown
7087+
| ^ punctuation.definition.metadata.begin.markdown
7088+
| ^^^^^^^^^^^^^^^^ markup.underline.link.image.markdown
7089+
| ^ punctuation.definition.metadata.end.markdown
7090+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.image.inline.attributes.markdown
7091+
| ^ punctuation.definition.attributes.begin.markdown
7092+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute-with-value.markdown
7093+
| ^^^^^^^^^^^ entity.other.attribute-name.markdown
7094+
| ^^^^^^ entity.other.attribute-name.markdown
7095+
| ^ punctuation.separator.key-value.markdown
7096+
| ^^^^^^^ string.unquoted.markdown
7097+
| ^ punctuation.definition.attributes.end.markdown
7098+
| ^^ punctuation.definition.highlight.end.markdown
7099+
70607100
70617101
# TEST: STRIKETHROUGH #########################################################
70627102
@@ -7168,6 +7208,27 @@ A ~~![highlight](https://image-url)~~
71687208
A ~~[![highlight](image-url)](link-url)~~
71697209
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.paragraph.markdown markup.strikethrough.markdown-gfm
71707210
7211+
A ~~![image $\ce{H2O}$.](./img/image6.png){#fig:image6 height=12.09cm }~~
7212+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.strikethrough.markdown-gfm
7213+
| ^^ punctuation.definition.strikethrough.begin.markdown
7214+
| ^^^^^^^^^^^^^^^^^^^^ meta.image.inline.description.markdown
7215+
| ^^ punctuation.definition.image.begin.markdown
7216+
| ^^^^^^^^^^ markup.math.inline.markdown text.tex.latex.embedded.markdown meta.environment.math.block.dollar.latex
7217+
| ^ punctuation.definition.image.end.markdown
7218+
| ^^^^^^^^^^^^^^^^^^ meta.image.inline.metadata.markdown
7219+
| ^ punctuation.definition.metadata.begin.markdown
7220+
| ^^^^^^^^^^^^^^^^ markup.underline.link.image.markdown
7221+
| ^ punctuation.definition.metadata.end.markdown
7222+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.image.inline.attributes.markdown
7223+
| ^ punctuation.definition.attributes.begin.markdown
7224+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute-with-value.markdown
7225+
| ^^^^^^^^^^^ entity.other.attribute-name.markdown
7226+
| ^^^^^^ entity.other.attribute-name.markdown
7227+
| ^ punctuation.separator.key-value.markdown
7228+
| ^^^^^^^ string.unquoted.markdown
7229+
| ^ punctuation.definition.attributes.end.markdown
7230+
| ^^ punctuation.definition.strikethrough.end.markdown
7231+
71717232
71727233
# TEST: LINKS #################################################################
71737234
@@ -7548,6 +7609,90 @@ Here is a ![Image Ref Alt][1].
75487609
| ^ markup.underline.link.markdown
75497610
| ^ punctuation.definition.metadata.end.markdown
75507611
7612+
A complex ![image $\ce{H2O}$.](./img/image6.png){#fig:image6 height=12.09cm }
7613+
| ^^^^^^^^^^^^^^^^^^^^ meta.image.inline.description.markdown
7614+
| ^^ punctuation.definition.image.begin.markdown
7615+
| ^^^^^^^^^^ markup.math.inline.markdown text.tex.latex.embedded.markdown meta.environment.math.block.dollar.latex
7616+
| ^ punctuation.definition.image.end.markdown
7617+
| ^^^^^^^^^^^^^^^^^^ meta.image.inline.metadata.markdown
7618+
| ^ punctuation.definition.metadata.begin.markdown
7619+
| ^^^^^^^^^^^^^^^^ markup.underline.link.image.markdown
7620+
| ^ punctuation.definition.metadata.end.markdown
7621+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.image.inline.attributes.markdown
7622+
| ^ punctuation.definition.attributes.begin.markdown
7623+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute-with-value.markdown
7624+
| ^^^^^^^^^^^ entity.other.attribute-name.markdown
7625+
| ^^^^^^ entity.other.attribute-name.markdown
7626+
| ^ punctuation.separator.key-value.markdown
7627+
| ^^^^^^^ string.unquoted.markdown
7628+
| ^ punctuation.definition.attributes.end.markdown
7629+
7630+
With codepsan ![`a`b]()
7631+
| ^^^^^^^ meta.image.inline.description.markdown
7632+
| ^^ punctuation.definition.image.begin.markdown
7633+
| ^^^ markup.raw.inline.markdown
7634+
| ^ punctuation.definition.raw.begin.markdown
7635+
| ^ punctuation.definition.raw.end.markdown
7636+
| ^ punctuation.definition.image.end.markdown
7637+
| ^^ meta.image.inline.metadata.markdown
7638+
| ^ punctuation.definition.metadata.begin.markdown
7639+
| ^ punctuation.definition.metadata.end.markdown
7640+
7641+
With codepsan ![``a`b``]()
7642+
| ^^^^^^^^^^ meta.image.inline.description.markdown
7643+
| ^^ punctuation.definition.image.begin.markdown
7644+
| ^^^^^^^ markup.raw.inline.markdown
7645+
| ^^ punctuation.definition.raw.begin.markdown
7646+
| ^^ punctuation.definition.raw.end.markdown
7647+
| ^ punctuation.definition.image.end.markdown
7648+
| ^^ meta.image.inline.metadata.markdown
7649+
| ^ punctuation.definition.metadata.begin.markdown
7650+
| ^ punctuation.definition.metadata.end.markdown
7651+
7652+
With codepsan ![` `]()
7653+
| ^^^^^^ meta.image.inline.description.markdown
7654+
| ^^ punctuation.definition.image.begin.markdown
7655+
| ^^^ markup.raw.inline.markdown
7656+
| ^ punctuation.definition.raw.begin.markdown
7657+
| ^ punctuation.definition.raw.end.markdown
7658+
| ^ punctuation.definition.image.end.markdown
7659+
| ^^ meta.image.inline.metadata.markdown
7660+
| ^ punctuation.definition.metadata.begin.markdown
7661+
| ^ punctuation.definition.metadata.end.markdown
7662+
7663+
With codepsan ![`` ` ``]()
7664+
| ^^^^^^^^^^ meta.image.inline.description.markdown
7665+
| ^^ punctuation.definition.image.begin.markdown
7666+
| ^^^^^^^ markup.raw.inline.markdown
7667+
| ^^ punctuation.definition.raw.begin.markdown
7668+
| ^^ punctuation.definition.raw.end.markdown
7669+
| ^ punctuation.definition.image.end.markdown
7670+
| ^^ meta.image.inline.metadata.markdown
7671+
| ^ punctuation.definition.metadata.begin.markdown
7672+
| ^ punctuation.definition.metadata.end.markdown
7673+
7674+
With codepsan ![``` `` ```]()
7675+
| ^^^^^^^^^^^^^ meta.image.inline.description.markdown
7676+
| ^^ punctuation.definition.image.begin.markdown
7677+
| ^^^^^^^^^^ markup.raw.inline.markdown
7678+
| ^^^ punctuation.definition.raw.begin.markdown
7679+
| ^^^ punctuation.definition.raw.end.markdown
7680+
| ^ punctuation.definition.image.end.markdown
7681+
| ^^ meta.image.inline.metadata.markdown
7682+
| ^ punctuation.definition.metadata.begin.markdown
7683+
| ^ punctuation.definition.metadata.end.markdown
7684+
7685+
With codepsan ![```` ``` ````]()
7686+
| ^^^^^^^^^^^^^^^^ meta.image.inline.description.markdown
7687+
| ^^ punctuation.definition.image.begin.markdown
7688+
| ^^^^^^^^^^^^^ markup.raw.inline.markdown
7689+
| ^^^^ punctuation.definition.raw.begin.markdown
7690+
| ^^^^ punctuation.definition.raw.end.markdown
7691+
| ^ punctuation.definition.image.end.markdown
7692+
| ^^ meta.image.inline.metadata.markdown
7693+
| ^ punctuation.definition.metadata.begin.markdown
7694+
| ^ punctuation.definition.metadata.end.markdown
7695+
75517696
75527697
# TEST: FOOTNOTES #############################################################
75537698

0 commit comments

Comments
 (0)