Skip to content

Commit 8b1f4a9

Browse files
committed
Merge branch 'st4-develop'
2 parents 8bd9216 + ab34fea commit 8b1f4a9

9 files changed

Lines changed: 231 additions & 87 deletions

Preferences.sublime-settings

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@
124124
// MarkdownEditing (Folding):
125125
// Selector for urls to automatically fold
126126
"mde.auto_fold_link.selector": "( meta.image.inline.metadata.markdown | meta.image.reference.metadata.markdown | meta.link.inline.metadata.markdown | meta.link.reference.metadata.markdown ) - punctuation.definition.metadata",
127+
// MarkdownEditing (Folding):
128+
// Automatically fold sections when loading new document
129+
// false: disable auto-folding on load
130+
// true: fold headings by level 1
131+
// 0: fold all sections, but keep headings visible (outline/toc mode, like ctrl+k, ctrl+9)
132+
// 1..6: fold headings by level (like ctrl+k, ctrl+1..6)
133+
"mde.auto_fold_sections.level": false,
127134

128135
// MarkdownEditing (Wiki):
129136
// wiki file extensions

docs/usage.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,25 @@ The folding selector can be tweaked in order to add or remove certain kinds of u
189189
"mde.auto_fold_link.selector": "( meta.image | meta.link ) & ( markup.underline | constant.other) - meta.link.reference.footnote - meta.link.reference.def - meta.link.inet",
190190
```
191191

192+
## Automatic Section Folding
193+
194+
MarkdownEditing can automatically fold sections when loading a document.
195+
196+
To globally enable it, add the following setting to _Perferences.sublime-settings_
197+
198+
```jsonc
199+
"mde.auto_fold_sections.level": 0, // TOC mode
200+
```
201+
202+
Valid values are:
203+
204+
| Value | Description
205+
| :---: | ---
206+
| false | disable auto-folding on load
207+
| true | fold headings by level 1
208+
| 0 | fold all sections, but keep headings visible (outline/toc mode, like <kbd>ctrl+k, ctrl+9</kbd>)
209+
| 1..6 | fold headings by level (like <kbd>ctrl+k, ctrl+1..6</kbd>)
210+
192211
## Navigation
193212

194213
MarkdownEditing provides various ways to navigate between sections.

make.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ goto :usage
9696

9797
:: create the release
9898
call git push --tags --force
99-
gh release create --target master -t "%package% %2" "%2" %assets%
99+
gh release create --target master -t "%package% %2" "%build%-%2" %assets%
100100
del /f /q *.sublime-package
101101
git fetch
102102
goto :eof

plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
MdeSelectColorSchemeCommand,
2929
)
3030
from .plugins.folding import (
31+
MdeAutoFoldListener,
3132
MdeFoldAllSectionsCommand,
3233
MdeFoldLinksCommand,
33-
MdeFoldLinksListener,
3434
MdeFoldSectionCommand,
3535
MdeShowFoldAllSectionsCommand,
3636
MdeUnfoldAllSectionsCommand,

plugins/folding.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -395,38 +395,44 @@ def run(self, edit, fold=None):
395395
unfold_urls(self.view)
396396

397397

398-
class MdeFoldLinksListener(MdeViewEventListener):
398+
class MdeAutoFoldListener(MdeViewEventListener):
399399
"""
400400
This class describes an automatic link folding event listener.
401401
"""
402402

403-
def auto_fold(self):
404-
settings = self.view.settings()
405-
if settings.get("mde.auto_fold_link.enabled", True):
403+
def auto_fold_links(self):
404+
if self.view.settings().get("mde.auto_fold_link.enabled", True):
406405
fold_urls(self.view)
407406
else:
408407
unfold_urls(self.view)
409408

409+
def auto_fold_sections(self):
410+
level = self.view.settings().get("mde.auto_fold_sections.level", False)
411+
if level is not False and 0 <= int(level) <= 6:
412+
self.view.run_command("mde_fold_all_sections", {"target_level": level})
413+
410414
def on_init(self):
411415
"""
412416
Fold all links after application startup.
413417
"""
414-
self.auto_fold()
418+
self.auto_fold_sections()
419+
self.auto_fold_links()
415420

416421
def on_load(self):
417422
"""
418423
Fold all links once file is loaded.
419424
"""
420-
self.auto_fold()
425+
self.auto_fold_sections()
426+
self.auto_fold_links()
421427

422428
def on_activated(self):
423429
"""
424430
Update link folding when activating view.
425431
"""
426-
self.auto_fold()
432+
self.auto_fold_links()
427433

428434
def on_selection_modified(self):
429435
"""
430436
Update link folding when moving caret around.
431437
"""
432-
self.auto_fold()
438+
self.auto_fold_links()

syntaxes/Fold.tmPreferences

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
<key>excludeTrailingNewlines</key>
2424
<true/>
2525
</dict>
26+
<dict>
27+
<key>begin</key>
28+
<string>punctuation.section.block.begin.markdown</string>
29+
<key>end</key>
30+
<string>punctuation.section.block.end.markdown</string>
31+
<key>excludeTrailingNewlines</key>
32+
<false/>
33+
</dict>
2634
</array>
2735
</dict>
2836
</dict>

syntaxes/Markdown.sublime-syntax

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ variables:
166166
)
167167
fenced_code_block_escape: ^{{fenced_code_block_end}}
168168

169+
# https://pandoc.org/MANUAL.html#divs-and-spans
170+
fenced_div_block: :{3,}
171+
169172
# https://spec.commonmark.org/0.30/#email-autolink
170173
email_domain_commonmark: '[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?'
171174
email_user_commonmark: '[a-zA-Z0-9.!#$%&''*+/=?^_`{|}~-]+'
@@ -256,6 +259,7 @@ variables:
256259
| {{block_quote}} # a blockquote begins the line
257260
| {{atx_heading}} # an ATX heading begins the line
258261
| {{fenced_code_block_start}} # a fenced codeblock begins the line
262+
| {{fenced_div_block}} # a fenced div block begins the line
259263
| {{thematic_break}} # line is a thematic beak
260264
| {{first_list_item}} # a list item begins the line
261265
| {{html_block}} # a html block begins the line
@@ -269,6 +273,7 @@ variables:
269273
| {{block_quote}} # a blockquote begins the line
270274
| {{atx_heading}} # an ATX heading begins the line
271275
| {{fenced_code_block_start}} # a fenced codeblock begins the line
276+
| {{fenced_div_block}} # a fenced div block begins the line
272277
| {{thematic_break}} # line is a thematic beak
273278
| {{list_item}} # a list item begins the line
274279
| {{html_block}} # a html block begins the line
@@ -362,6 +367,7 @@ contexts:
362367
- include: list-blocks
363368
- include: tables
364369
- include: fenced-code-blocks
370+
- include: fenced-div-blocks
365371
- include: html-blocks
366372
- include: reference-definitions
367373
- include: atx-headings
@@ -594,6 +600,7 @@ contexts:
594600
| {{reference_definition}} # a reference definition begins the line
595601
| {{atx_heading}} # an ATX heading begins the line
596602
| {{fenced_code_block_start}} # a fenced codeblock begins the line
603+
| {{fenced_div_block}} # a fenced div block begins the line
597604
| {{thematic_break}} # line is a thematic beak
598605
| {{list_item}} # a list item begins the line
599606
| {{html_block}} # a html block begins the line
@@ -705,6 +712,7 @@ contexts:
705712
(?: $ # the line is blank (or only contains whitespace)
706713
| {{atx_heading}} # an ATX heading begins the line
707714
| {{fenced_code_block_start}} # a fenced codeblock begins the line
715+
| {{fenced_div_block}} # a fenced div block begins the line
708716
| {{thematic_break}} # line is a thematic beak
709717
| {{list_item}} # a list item begins the line
710718
| {{html_block}} # a html block begins the line
@@ -732,6 +740,7 @@ contexts:
732740
(?: \s* $ # the line is blank (or only contains whitespace)
733741
| {{atx_heading}} # an ATX heading begins the line
734742
| {{fenced_code_block_start}} # a fenced codeblock begins the line
743+
| {{fenced_div_block}} # a fenced div block begins the line
735744
| {{thematic_break}} # line is a thematic beak
736745
| {{list_item}} # a list item begins the line
737746
| {{html_block}} # a html block begins the line
@@ -1147,7 +1156,6 @@ contexts:
11471156
- include: fenced-rust
11481157
- include: fenced-scala
11491158
- include: fenced-shell
1150-
- include: fenced-shell-script
11511159
- include: fenced-sql
11521160
- include: fenced-tsx
11531161
- include: fenced-typescript
@@ -2007,46 +2015,24 @@ contexts:
20072015
- match: |-
20082016
(?x)
20092017
{{fenced_code_block_start}}
2010-
(?i:\s*(console|shell))
2018+
(?i:\s*(console|bash|shell(?:-script)?|sh)|zsh)
20112019
{{fenced_code_block_trailing_infostring_characters}}
20122020
captures:
20132021
0: meta.code-fence.definition.begin.shell.markdown-gfm
20142022
2: punctuation.definition.raw.code-fence.begin.markdown
20152023
5: constant.other.language-name.markdown
20162024
6: comment.line.infostring.markdown
20172025
7: meta.fold.code-fence.begin.markdown
2018-
embed: scope:source.shell.interactive.markdown
2026+
embed: scope:source.shell.embedded.markdown
20192027
embed_scope:
20202028
markup.raw.code-fence.shell.markdown-gfm
2021-
source.shell.interactive.markdown
2029+
source.shell
20222030
escape: '{{fenced_code_block_escape}}'
20232031
escape_captures:
20242032
0: meta.code-fence.definition.end.shell.markdown-gfm
20252033
1: punctuation.definition.raw.code-fence.end.markdown
20262034
2: meta.fold.code-fence.end.markdown
20272035
2028-
fenced-shell-script:
2029-
- match: |-
2030-
(?x)
2031-
{{fenced_code_block_start}}
2032-
(?i:\s*(shell-script|sh|bash|zsh))
2033-
{{fenced_code_block_trailing_infostring_characters}}
2034-
captures:
2035-
0: meta.code-fence.definition.begin.shell-script.markdown-gfm
2036-
2: punctuation.definition.raw.code-fence.begin.markdown
2037-
5: constant.other.language-name.markdown
2038-
6: comment.line.infostring.markdown
2039-
7: meta.fold.code-fence.begin.markdown
2040-
embed: scope:source.shell.bash
2041-
embed_scope:
2042-
markup.raw.code-fence.shell-script.markdown-gfm
2043-
source.shell.bash
2044-
escape: '{{fenced_code_block_escape}}'
2045-
escape_captures:
2046-
0: meta.code-fence.definition.end.shell-script.markdown-gfm
2047-
1: punctuation.definition.raw.code-fence.end.markdown
2048-
2: meta.fold.code-fence.end.markdown
2049-
20502036
fenced-sql:
20512037
- match: |-
20522038
(?x)
@@ -3090,6 +3076,7 @@ contexts:
30903076
| {{reference_definition}} # a reference definition begins the line
30913077
| {{atx_heading}} # an ATX heading begins the line
30923078
| {{fenced_code_block_start}} # a fenced codeblock begins the line
3079+
| {{fenced_div_block}} # a fenced div block begins the line
30933080
| {{thematic_break}} # line is a thematic beak
30943081
| {{list_item}} # a list item begins the line
30953082
| {{html_block}} # a html block begins the line
@@ -3205,6 +3192,7 @@ contexts:
32053192
| {{atx_heading}}
32063193
| {{block_quote}}
32073194
| {{fenced_code_block_start}}
3195+
| {{fenced_div_block}}
32083196
| {{indented_code_block}}
32093197
| {{thematic_break}}
32103198
)
@@ -4368,6 +4356,46 @@ contexts:
43684356
- include: scope:text.tex.latex#macros
43694357
- include: scope:text.tex.latex#math-content
43704358

4359+
###[ EXTENSIONS: PANDOC FENCED DIVS ]##########################################
4360+
4361+
fenced-div-blocks:
4362+
# https://pandoc.org/MANUAL.html#divs-and-spans
4363+
- match: ^[ \t]*({{fenced_div_block}})[ \t]*(?=\S)
4364+
captures:
4365+
1: punctuation.section.block.begin.markdown
4366+
push:
4367+
- fenced-div-body
4368+
- fenced-div-puncuation
4369+
- fenced-div-attr
4370+
4371+
fenced-div-attr:
4372+
- meta_include_prototype: false
4373+
- match: \{
4374+
scope: punctuation.definition.attributes.begin.markdown
4375+
set: link-def-attr-body
4376+
- match: '{{tag_attribute_name_start}}'
4377+
set:
4378+
- tag-attr-meta
4379+
- tag-attr-equals
4380+
- tag-attr-name
4381+
- match: else-pop
4382+
4383+
fenced-div-puncuation:
4384+
- meta_include_prototype: false
4385+
- match: ':+'
4386+
scope: punctuation.section.block.markdown
4387+
pop: 1
4388+
- include: else-pop
4389+
4390+
fenced-div-body:
4391+
- meta_include_prototype: false
4392+
- meta_scope: meta.block.div.markdown
4393+
- match: ^[ \t]*(\1)(\s*\n)
4394+
captures:
4395+
1: punctuation.section.block.end.markdown
4396+
pop: 1
4397+
- include: markdown
4398+
43714399
###[ PROTOTYPES ]#############################################################
43724400

43734401
else-pop:
@@ -4386,4 +4414,3 @@ contexts:
43864414
immediately-pop:
43874415
- match: ''
43884416
pop: 1
4389-
Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
%YAML 1.2
22
---
3-
name: Interactive Unix Shell
4-
scope: source.shell.interactive.markdown
3+
scope: source.shell.embedded.markdown
54
version: 2
65
hidden: true
76

87
extends: Packages/ShellScript/Shell-Unix-Generic.sublime-syntax
98

109
contexts:
11-
prototype:
12-
- meta_prepend: true
13-
# continuation lines begin with `> `
14-
- match: ^\s*(>)\s
15-
captures:
16-
1: comment.other.shell
17-
1810
main:
11+
- meta_include_prototype: false
12+
# found shebang => normal script
13+
- match: ^(?=\s*#!)
14+
set: [statements, shebang]
15+
# first non-comment line starts with `$` => interactive shell
1916
- match: ^(?=\s*\$\s)
20-
push: shell-interactive
21-
- include: statements
17+
set: shell-interactive
18+
# some script without shebang
19+
- match: ^(?=\s*[^#])
20+
set: statements
21+
- include: comments
2222

2323
shell-interactive:
2424
- match: ^\s*(\$)(?=\s)
2525
captures:
2626
1: comment.other.shell
2727
embed: statements
28-
escape: (?<![^\\]\\)(?<![\\]{3})\n
28+
escape: '{{no_escape_behind}}\n'
2929

3030
line-continuation-body:
3131
- meta_prepend: true
32-
- meta_include_prototype: false
33-
# continuation lines begin with `> `
32+
# continuation line of interactive shells begin with `> `
3433
- match: ^\s*(>)\s
3534
captures:
3635
1: comment.other.shell
3736
pop: 1
37+
38+
variables:
39+
# lazy escaping from heredoc as shell maybe indented
40+
no_indent: ^\s*
41+
tab_indent: ^\s*

0 commit comments

Comments
 (0)