From ab3355d2a28224d202d667b66f24a25462ddf628 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Wed, 22 Feb 2017 11:28:16 +0200 Subject: [PATCH] [Markdown] support multi line link titles useful for comments when people don't want to use HTML comments - see https://github.com/SublimeText-Markdown/MarkdownEditing/issues/409 --- Markdown/Markdown.sublime-syntax | 65 ++++++++++++++++++++++++-------- Markdown/syntax_test_markdown.md | 40 +++++++++++++++++++- 2 files changed, 88 insertions(+), 17 deletions(-) diff --git a/Markdown/Markdown.sublime-syntax b/Markdown/Markdown.sublime-syntax index 77f68a2bff..384eb9434b 100644 --- a/Markdown/Markdown.sublime-syntax +++ b/Markdown/Markdown.sublime-syntax @@ -113,12 +113,11 @@ contexts: \s* # Leading whitespace (\[)(.+?)(\])(:) # Reference name [ \t]* # Optional whitespace - (?) # 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 @@ -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 @@ -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: @@ -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 diff --git a/Markdown/syntax_test_markdown.md b/Markdown/syntax_test_markdown.md index 39abe5fe92..e0bc6d9964 100644 --- a/Markdown/syntax_test_markdown.md +++ b/Markdown/syntax_test_markdown.md @@ -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 @@ -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]: "test" +| ^ punctuation.definition.link.begin +| ^^^ markup.underline.link +| ^ punctuation.definition.link.end +| ^^^^^^ string.other.link.description.title + +[foo]: > "test" +| ^ punctuation.definition.link.begin +| ^^^ markup.underline.link +| ^ punctuation.definition.link.end +| ^^^^^^^^ invalid.illegal.expected-eol