From 855274f8325bd114969e5774848aafd548f11cc2 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sat, 19 Nov 2022 12:47:32 +0100 Subject: [PATCH 1/6] [Markdown] Fix GFM auto-link termination This commit adds some undocumented punctuation to the set of terminating autolink characters. --- syntaxes/Markdown.sublime-syntax | 8 +-- tests/syntax_test_markdown.md | 86 ++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 3 deletions(-) diff --git a/syntaxes/Markdown.sublime-syntax b/syntaxes/Markdown.sublime-syntax index 99a1cd2d..682d5844 100644 --- a/syntaxes/Markdown.sublime-syntax +++ b/syntaxes/Markdown.sublime-syntax @@ -3283,6 +3283,7 @@ contexts: - link-url-scheme-separator # Github Flavoured Markdown # After a valid domain, zero or more non-space non-< characters may follow + # https://github.github.com/gfm/#autolinks-extension- - match: (?:(?:https|http|ftp)(://)|www\.)[\w-]+ captures: 1: punctuation.separator.path.markdown @@ -3311,14 +3312,15 @@ contexts: # 3. Trailing punctuation (specifically, ?, !, ., ,, :, *, _, and ~) will not # be considered part of the autolink, though they may be included in the # interior # of the link - - match: (?=(?:\)|(?:{{html_entity}})*)[?!.,:*_~]*[\s<]) + # Note: contains some empirical (undocumented) punctuation such as ;, ', " + - match: (?=(?:\)|(?:{{html_entity}})*)[?!.,:;*_~'"]*[\s<]) pop: true - include: autolink-inet-common autolink-inet-group: - match: \) - pop: true - - match: (?=(?:{{html_entity}})*[?!.,:*_~]*[\s<]) + pop: 1 + - match: (?=(?:{{html_entity}})*[?!.,:;*_~'"]*[\s<]) pop: true - include: autolink-inet-common diff --git a/tests/syntax_test_markdown.md b/tests/syntax_test_markdown.md index 6e466e92..6d393ad1 100644 --- a/tests/syntax_test_markdown.md +++ b/tests/syntax_test_markdown.md @@ -7358,6 +7358,92 @@ Visit www.commonmark.org/a.b. | ^ - markup.underline.link | ^ punctuation.separator.path.markdown +Visit www.commonmark.org? +| ^ - markup.underline.link +| ^^^^^^^^^^^^^^^^^^ meta.paragraph meta.link.inet.markdown markup.underline.link +| ^ - markup.underline.link + +Visit www.commonmark.org! +| ^ - markup.underline.link +| ^^^^^^^^^^^^^^^^^^ meta.paragraph meta.link.inet.markdown markup.underline.link +| ^ - markup.underline.link + +Visit www.commonmark.org: +| ^ - markup.underline.link +| ^^^^^^^^^^^^^^^^^^ meta.paragraph meta.link.inet.markdown markup.underline.link +| ^ - markup.underline.link + +Visit www.commonmark.org; +| ^ - markup.underline.link +| ^^^^^^^^^^^^^^^^^^ meta.paragraph meta.link.inet.markdown markup.underline.link +| ^ - markup.underline.link + +Visit www.commonmark.org* +| ^ - markup.underline.link +| ^^^^^^^^^^^^^^^^^^ meta.paragraph meta.link.inet.markdown markup.underline.link +| ^ - markup.underline.link + +Visit www.commonmark.org_ +| ^ - markup.underline.link +| ^^^^^^^^^^^^^^^^^^ meta.paragraph meta.link.inet.markdown markup.underline.link +| ^ - markup.underline.link + +Visit www.commonmark.org~ +| ^ - markup.underline.link +| ^^^^^^^^^^^^^^^^^^ meta.paragraph meta.link.inet.markdown markup.underline.link +| ^ - markup.underline.link + +Visit 'www.commonmark.org' +| ^ - markup.underline.link +| ^^^^^^^^^^^^^^^^^^ meta.paragraph meta.link.inet.markdown markup.underline.link +| ^ - markup.underline.link + +Visit "www.commonmark.org" +| ^ - markup.underline.link +| ^^^^^^^^^^^^^^^^^^ meta.paragraph meta.link.inet.markdown markup.underline.link +| ^ - markup.underline.link + +Visit "www.commonmark.org/q'uo"te" +| ^ - markup.underline.link +| ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.paragraph meta.link.inet.markdown markup.underline.link +| ^ - markup.underline.link +Visit www.commonmark.org= +| ^ - markup.underline.link +| ^^^^^^^^^^^^^^^^^^^ meta.paragraph meta.link.inet.markdown markup.underline.link +| ^ - markup.underline.link + +Visit www.commonmark.org& +| ^ - markup.underline.link +| ^^^^^^^^^^^^^^^^^^^ meta.paragraph meta.link.inet.markdown markup.underline.link +| ^ - markup.underline.link + +Visit www.commonmark.org% +| ^ - markup.underline.link +| ^^^^^^^^^^^^^^^^^^^ meta.paragraph meta.link.inet.markdown markup.underline.link +| ^ - markup.underline.link + +Visit www.commonmark.org$ +| ^ - markup.underline.link +| ^^^^^^^^^^^^^^^^^^^ meta.paragraph meta.link.inet.markdown markup.underline.link +| ^ - markup.underline.link + +Visit www.commonmark.org# +| ^ - markup.underline.link +| ^^^^^^^^^^^^^^^^^^^ meta.paragraph meta.link.inet.markdown markup.underline.link +| ^ - markup.underline.link + +www.google.com/search?q=(business' +|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.link.inet.markdown markup.underline.link +| ^ punctuation.separator.path.markdown +| ^ punctuation.separator.path.markdown +| ^ - markup.underline.link + +www.google.com/search?q=(business" +|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.link.inet.markdown markup.underline.link +| ^ punctuation.separator.path.markdown +| ^ punctuation.separator.path.markdown +| ^ - markup.underline.link + www.google.com/search?q=(business))+ok |^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.link.inet.markdown markup.underline.link | ^ punctuation.separator.path.markdown From 93a5678886a1374f5fea7c143c72074bbea9544d Mon Sep 17 00:00:00 2001 From: deathaxe Date: Tue, 22 Nov 2022 20:06:59 +0100 Subject: [PATCH 2/6] Syntax: Add support for pandoc attributes in link defs Fixes #712 --- syntaxes/Markdown.sublime-syntax | 26 +++++++++++++++++++++--- tests/syntax_test_markdown.md | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/syntaxes/Markdown.sublime-syntax b/syntaxes/Markdown.sublime-syntax index 682d5844..a75892a3 100644 --- a/syntaxes/Markdown.sublime-syntax +++ b/syntaxes/Markdown.sublime-syntax @@ -2431,25 +2431,44 @@ contexts: 3: punctuation.definition.reference.end.markdown 4: punctuation.separator.key-value.markdown push: - - link-def-end + - link-def-meta + - link-def-attr - link-def-title - link-def-url - link-def-end: + link-def-meta: - meta_include_prototype: false - meta_scope: meta.link.reference.def.markdown - include: immediately-pop + link-def-attr: + - match: \{ + scope: punctuation.definition.attributes.begin.markdown + set: link-def-attr-body + - match: ^(?!\s*{)|(?=\S) + pop: 1 + + link-def-attr-body: + - meta_scope: meta.attributes.markdown + - include: tag-attributes + link-def-title: - match: ^(?!\s*["'(]) pop: true - match: (?=["'(]) set: - - expect-eol + - expect-attr-or-eol - link-title + - match: (?=\{) + pop: 1 - match: \S.+ scope: invalid.illegal.expected-eol.markdown + expect-attr-or-eol: + - match: (?=\{) + pop: 1 + - include: expect-eol + link-def-url: - match: < scope: punctuation.definition.link.begin.markdown @@ -3206,6 +3225,7 @@ contexts: scope: invalid.illegal.attribute-name.markdown tag-attr-meta: + - meta_include_prototype: false - meta_scope: meta.attribute-with-value.markdown - include: immediately-pop diff --git a/tests/syntax_test_markdown.md b/tests/syntax_test_markdown.md index 6d393ad1..9e463855 100644 --- a/tests/syntax_test_markdown.md +++ b/tests/syntax_test_markdown.md @@ -2508,6 +2508,41 @@ Foo | ^ punctuation.separator.key-value.markdown | ^^^^ markup.underline.link.markdown +## https://custom-tests/link-reference-definitions/with-attributes + +[link]: /url {#id .class width=30} +| ^^^^^^^^^^^^^^^^^^^^^ meta.link.reference.def.markdown meta.attributes.markdown + +[link]: /url (description) {#id .class width=30} +| ^^^^^^^^^^^^^^^^^^^^^ meta.link.reference.def.markdown meta.attributes.markdown + +[link]: /url "description" {#id .class width=30} +| ^^^^^^^^^^^^^^^^^^^^^ meta.link.reference.def.markdown meta.attributes.markdown + +[link]: + /url + {#id .class width=30} +| ^^^^^^^^^^^^^^^^^^^^^ meta.link.reference.def.markdown meta.attributes.markdown + +[link]: + /url + + {#id .class width=30} +| ^^^^^^^^^^^^^^^^^^^^^ - meta.link - meta.attributes + +[link]: + /url + "description" + {#id .class width=30} +| ^^^^^^^^^^^^^^^^^^^^^ meta.link.reference.def.markdown meta.attributes.markdown + +[link]: + /url + "description" + + {#id .class width=30} +| ^^^^^^^^^^^^^^^^^^^^^ - meta.link - meta.attributes + ## https://custom-tests/link-reference-definitions/in-block-quotes > [foo]: /url "description" From cd1112bc2bdadd053a900cfa4e5bd47095188943 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Wed, 23 Nov 2022 20:42:49 +0100 Subject: [PATCH 3/6] Satisfy linter --- plugins/headings/common.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/headings/common.py b/plugins/headings/common.py index f8a1b01d..d23249e2 100644 --- a/plugins/headings/common.py +++ b/plugins/headings/common.py @@ -57,7 +57,9 @@ class MdeUnsavedViewNameSetter(MdeViewEventListener): MAX_NAME = 50 def on_modified(self): - if self.view.file_name() is not None or not self.view.settings().get("set_unsaved_view_name", True): + if self.view.file_name() is not None or not self.view.settings().get( + "set_unsaved_view_name", True + ): return name = first_heading_text(self.view) From b4279944b56da3cff9027fb16c202cf05733b3c0 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Wed, 23 Nov 2022 20:57:54 +0100 Subject: [PATCH 4/6] Add changelog --- messages.json | 3 ++- messages/3.1.8.md | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 messages/3.1.8.md diff --git a/messages.json b/messages.json index ec9077b6..55d95510 100644 --- a/messages.json +++ b/messages.json @@ -41,5 +41,6 @@ "3.1.4": "messages/3.1.4.md", "3.1.5": "messages/3.1.5.md", "3.1.6": "messages/3.1.6.md", - "3.1.7": "messages/3.1.7.md" + "3.1.7": "messages/3.1.7.md", + "3.1.8": "messages/3.1.8.md" } diff --git a/messages/3.1.8.md b/messages/3.1.8.md new file mode 100644 index 00000000..cebd2cb1 --- /dev/null +++ b/messages/3.1.8.md @@ -0,0 +1,15 @@ +# MarkdownEditing 3.1.8 Changelog + +Your _MarkdownEditing_ plugin is updated. Enjoy new version. For any type of +feedback you can use [GitHub issues][issues]. + +## Bug Fixes + +* Fix GFM auto-link termination +* Add support for pandoc attributes in reference definitions (#712) + +## New Features + +## Changes + +[issues]: https://github.com/SublimeText-Markdown/MarkdownEditing/issues From 0791cb68ce3838266589b1b2c98621bf0511497a Mon Sep 17 00:00:00 2001 From: deathaxe Date: Wed, 23 Nov 2022 21:10:04 +0100 Subject: [PATCH 5/6] Syntax: Fix ST3 compatibility `pop: 1` is not supported by ST3 --- syntaxes/Markdown.sublime-syntax | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/syntaxes/Markdown.sublime-syntax b/syntaxes/Markdown.sublime-syntax index a75892a3..f9eb9cab 100644 --- a/syntaxes/Markdown.sublime-syntax +++ b/syntaxes/Markdown.sublime-syntax @@ -2446,7 +2446,7 @@ contexts: scope: punctuation.definition.attributes.begin.markdown set: link-def-attr-body - match: ^(?!\s*{)|(?=\S) - pop: 1 + pop: true link-def-attr-body: - meta_scope: meta.attributes.markdown @@ -2460,13 +2460,13 @@ contexts: - expect-attr-or-eol - link-title - match: (?=\{) - pop: 1 + pop: true - match: \S.+ scope: invalid.illegal.expected-eol.markdown expect-attr-or-eol: - match: (?=\{) - pop: 1 + pop: true - include: expect-eol link-def-url: @@ -3339,7 +3339,7 @@ contexts: autolink-inet-group: - match: \) - pop: 1 + pop: true - match: (?=(?:{{html_entity}})*[?!.,:;*_~'"]*[\s<]) pop: true - include: autolink-inet-common From 0b18708c55a59729104b02e179b5423cd0efe80f Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 30 Oct 2022 17:23:48 +0100 Subject: [PATCH 6/6] Plugins: Modify heading style only before saving Fixes #710 --- plugins/headings/style.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/headings/style.py b/plugins/headings/style.py index 72b94761..32eb0fb2 100644 --- a/plugins/headings/style.py +++ b/plugins/headings/style.py @@ -66,6 +66,8 @@ def on_load(self): def on_pre_save(self): self.auto_detect_heading_style() + if self.view.settings().get("mde.auto_match_heading_hashes", False): + self.view.run_command("mde_match_heading_hashes") def auto_detect_heading_style(self): view = self.view @@ -86,6 +88,3 @@ def auto_detect_heading_style(self): view.settings().set("mde.match_heading_hashes", num_trailing / num_leading > 0.5) else: view.settings().erase("mde.match_heading_hashes") - - if view.settings().get("mde.auto_match_heading_hashes", False): - view.run_command("mde_match_heading_hashes")