Skip to content

Commit 7b258bf

Browse files
committed
Add Indentation rules
1 parent cc26e5e commit 7b258bf

File tree

2 files changed

+121
-5
lines changed

2 files changed

+121
-5
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Syntax highlighting
88
- Bracket matching
9+
- Indentation rules
910
- YAML versions [1.2](https://yaml.org/spec/1.2.2), [1.1](https://yaml.org/spec/1.1/), [1.0](https://yaml.org/spec/1.0/) and [1.3](https://spec.yaml.io/main/spec/1.3.0/)
1011

1112

@@ -14,6 +15,6 @@
1415
- Previously known [Issues](https://github.com/RedCMD/YAML-Syntax-Highlighter/issues/1)
1516
- Original YAML [grammar](https://github.com/textmate/yaml.tmbundle)
1617
- Atom's YAML [grammar](https://github.com/atom/language-yaml)
17-
- Offical YAML [website](https://yaml.org/)
18+
- Official YAML [website](https://yaml.org/)
1819
- Github [repo](https://github.com/RedCMD/YAML-Syntax-Highlighter)
1920
- Marketplace [extension](https://marketplace.visualstudio.com/items?itemName=RedCMD.yaml-syntax)

language-configuration.json

Lines changed: 119 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,130 @@
3232
["{", "}"],
3333
["[", "]"]
3434
],
35+
// markers that can be folded
3536
"folding": {
3637
"offSide": true,
3738
"markers": {
3839
"start": "^[ \t]*#[ \t]*region\\b|^---[ \t]*(#.*)?$",
3940
"end": "^[ \t]*#[ \t]*endregion\\b|^\\.{3}[ \t]*(#.*)?$"
4041
}
4142
},
42-
"indentationRules": {
43-
"increaseIndentPattern": "^\\s*.*(:|-) ?(&\\w+)?(\\{[^}\"']*|\\[[^\\]\"']*)?$",
44-
"decreaseIndentPattern": "^\\s+[\\]\\}]$"
45-
}
43+
// Only the first successful rule is chosen
44+
"onEnterRules": [
45+
{
46+
// indent 1 space after block-scalar with indentation-indicator
47+
"action": {
48+
"appendText": " ",
49+
"indent": "none",
50+
},
51+
"afterText": "^(?![ \t]*#)",
52+
"beforeText": "([ \t]+|^)[|>][+-]?1"
53+
},
54+
{
55+
"action": {
56+
"appendText": " ",
57+
"indent": "none",
58+
},
59+
"afterText": "^(?![ \t]*#)",
60+
"beforeText": "([ \t]+|^)[|>][+-]?2"
61+
},
62+
{
63+
"action": {
64+
"appendText": " ",
65+
"indent": "none",
66+
},
67+
"afterText": "^(?![ \t]*#)",
68+
"beforeText": "([ \t]+|^)[|>][+-]?3"
69+
},
70+
{
71+
"action": {
72+
"appendText": " ",
73+
"indent": "none",
74+
},
75+
"afterText": "^(?![ \t]*#)",
76+
"beforeText": "([ \t]+|^)[|>][+-]?4"
77+
},
78+
{
79+
"action": {
80+
"appendText": " ",
81+
"indent": "none",
82+
},
83+
"afterText": "^(?![ \t]*#)",
84+
"beforeText": "([ \t]+|^)[|>][+-]?5"
85+
},
86+
{
87+
"action": {
88+
"appendText": " ",
89+
"indent": "none",
90+
},
91+
"afterText": "^(?![ \t]*#)",
92+
"beforeText": "([ \t]+|^)[|>][+-]?6"
93+
},
94+
{
95+
"action": {
96+
"appendText": " ",
97+
"indent": "none",
98+
},
99+
"afterText": "^(?![ \t]*#)",
100+
"beforeText": "([ \t]+|^)[|>][+-]?7"
101+
},
102+
{
103+
"action": {
104+
"appendText": " ",
105+
"indent": "none",
106+
},
107+
"afterText": "^(?![ \t]*#)",
108+
"beforeText": "([ \t]+|^)[|>][+-]?8"
109+
},
110+
{
111+
// indent 9 spaces after block-scalar with indentation-indicator
112+
"action": {
113+
"appendText": " ",
114+
"indent": "none",
115+
},
116+
"afterText": "^(?![ \t]*#)",
117+
"beforeText": "([ \t]+|^)[|>][+-]?9"
118+
},
119+
{
120+
// - block-map: # with an empty value OR block-scalar. Prefixed with a block-seq
121+
"action": {
122+
"appendText": " ",
123+
"indent": "none"
124+
},
125+
"beforeText": "(^| |\t)-[ \t]+[^#,\\[\\]{}].*:(([ \t]+[|>][+-]?)?([ \t]+#.*)?|[ \t]*)$"
126+
},
127+
{
128+
// indent 2 spaces after non-root block-scalar
129+
"action": {
130+
"appendText": " ",
131+
"indent": "none",
132+
},
133+
"afterText": "^(?![ \t]*#)",
134+
"beforeText": "[-?:][ \t]+[|>][+-]?[ \t]*(#.*)?$"
135+
},
136+
{
137+
// block-map: cursor_must_be_before_value
138+
"action": {
139+
"appendText": " ",
140+
"indent": "none"
141+
},
142+
"beforeText": "(?<!( |\t|^)(#|\\?[ \t]).*):([ \t]*|[ \t]+#.*)$"
143+
},
144+
{
145+
// - #empty block-seq
146+
"action": {
147+
"appendText": " ",
148+
"indent": "none"
149+
},
150+
"beforeText": "(^| |\t)-([ \t]*|[ \t]+#.*)$"
151+
},
152+
{
153+
// - block-seq
154+
"action": {
155+
"appendText": "- ",
156+
"indent": "none"
157+
},
158+
"beforeText": "(^| |\t)-[ \t].*$"
159+
}
160+
]
46161
}

0 commit comments

Comments
 (0)