Skip to content

Commit

Permalink
[Markdown] support multi line link titles
Browse files Browse the repository at this point in the history
useful for comments when people don't want to use HTML comments - see SublimeText-Markdown/MarkdownEditing#409
  • Loading branch information
keith-hall committed Feb 22, 2017
1 parent 6724234 commit ab3355d
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 17 deletions.
65 changes: 50 additions & 15 deletions Markdown/Markdown.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,11 @@ contexts:
\s* # Leading whitespace
(\[)(.+?)(\])(:) # Reference name
[ \t]* # Optional whitespace
(<?)(\S+?)(>?) # The url
{{link_title}} # Optional link title
\s* # Optional whitespace
$
(?:
(<)([^>]+)(>) # The url
| (\S+) # The url
)
)
scope: meta.link.reference.def.markdown
captures:
1: punctuation.definition.constant.begin.markdown
2: constant.other.reference.link.markdown
Expand All @@ -127,15 +126,10 @@ contexts:
5: punctuation.definition.link.begin.markdown
6: markup.underline.link.markdown
7: punctuation.definition.link.end.markdown
8: string.other.link.description.title.markdown
9: punctuation.definition.string.begin.markdown
10: punctuation.definition.string.end.markdown
11: string.other.link.description.title.markdown
12: punctuation.definition.string.begin.markdown
13: punctuation.definition.string.end.markdown
14: string.other.link.description.title.markdown
15: punctuation.definition.string.begin.markdown
16: punctuation.definition.string.end.markdown
8: markup.underline.link.markdown
push:
- meta_scope: meta.link.reference.def.markdown
- include: link-title
- match: '^(?=\S)(?![=-]{3,}\s*$)'
push:
- meta_scope: meta.paragraph.markdown
Expand Down Expand Up @@ -433,7 +427,7 @@ contexts:
- match: '[*_]+'
hard-line-break:
- match: '[ ]{2,}$'
scope: meta.hard-line-break.markdown
scope: meta.hard-line-break.markdown punctuation.definition.hard-line-break.markdown
- match: '(\\)$\n'
scope: meta.hard-line-break.markdown
captures:
Expand Down Expand Up @@ -645,3 +639,44 @@ contexts:
- include: link-text
- include: image-inline
- include: image-ref
link-title:
- match: \s*(')
captures:
1: punctuation.definition.string.begin.markdown
push:
- meta_scope: string.other.link.description.title.markdown
- match: \'
scope: punctuation.definition.string.end.markdown
set: after-link-title
- match: ^\s*$\n?
scope: invalid.illegal.non-terminated.link-title.markdown
pop: true
- match: \s*(")
captures:
1: punctuation.definition.string.begin.markdown
push:
- meta_scope: string.other.link.description.title.markdown
- match: \"
scope: punctuation.definition.string.end.markdown
set: after-link-title
- match: ^\s*$\n?
scope: invalid.illegal.non-terminated.link-title.markdown
pop: true
- match: \s*(\()
captures:
1: punctuation.definition.string.begin.markdown
push:
- meta_scope: string.other.link.description.title.markdown
- match: \)
scope: punctuation.definition.string.end.markdown
set: after-link-title
- match: ^\s*$\n?
scope: invalid.illegal.non-terminated.link-title.markdown
pop: true
- match: \s*
set: after-link-title
after-link-title:
- match: '(.*)$\n?'
captures:
1: invalid.illegal.expected-eol.markdown
pop: true
40 changes: 38 additions & 2 deletions Markdown/syntax_test_markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -902,11 +902,11 @@ hello world ````test````
| ^ punctuation.definition.raw.end

hard line break
| ^^ meta.hard-line-break
| ^^ meta.hard-line-break punctuation.definition.hard-line-break
hard line break\
| ^ meta.hard-line-break constant.character.escape
hard line break
| ^^^^^ meta.hard-line-break
| ^^^^^ meta.hard-line-break punctuation.definition.hard-line-break
soft line break
| ^^ - meta.hard-line-break
soft line break
Expand Down Expand Up @@ -1042,3 +1042,39 @@ _foo [**bar**](/url)_
|^^^^^^^^^^^ meta.link.reference.def constant.other.reference.link
| ^ punctuation.separator.key-value
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.underline.link

[//]: # (This is a comment without a line-break.)
| ^ meta.link.reference.def markup.underline.link
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.other.link.description.title

[//]: # (This is a comment with a
| ^ meta.link.reference.def markup.underline.link
| ^ punctuation.definition.string.begin
line-break.)
| ^ punctuation.definition.string.end

[//]: # (testing)blah
| ^ punctuation.definition.string.begin
|^^^^^^^^^^^^^^^^ meta.link.reference.def
| ^ punctuation.definition.string.end
| ^^^^ invalid.illegal.expected-eol

[//]: # (testing
blah
| <- meta.link.reference.def string.other.link.description.title

| <- invalid.illegal.non-terminated.link-title
text
| <- meta.paragraph - meta.link.reference.def

[foo]: <bar> "test"
| ^ punctuation.definition.link.begin
| ^^^ markup.underline.link
| ^ punctuation.definition.link.end
| ^^^^^^ string.other.link.description.title

[foo]: <bar>> "test"
| ^ punctuation.definition.link.begin
| ^^^ markup.underline.link
| ^ punctuation.definition.link.end
| ^^^^^^^^ invalid.illegal.expected-eol

0 comments on commit ab3355d

Please sign in to comment.