Skip to content

Commit fe5d0d0

Browse files
committed
Fixed readme for custom tags fix
1 parent f325c88 commit fe5d0d0

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,38 @@ The following settings are supported:
3636
* `yaml.hover`: Enable/disable hover
3737
* `yaml.completion`: Enable/disable autocompletion
3838
* `yaml.schemas`: Helps you associate schemas with files in a glob pattern
39-
* `yaml.customTags`: Array of custom tags that the parser will validate against. It has two ways to be used. Either an item in the array is a custom tag such as "!Ref" or you can specify the type of the object !Ref should be by doing "!Ref Scalar". For example: ["!Ref", "!Some-Tag Scalar"]. The type of object can be one of Scalar, Sequence, Mapping, Map.
39+
* `yaml.customTags`: Array of custom tags that the parser will validate against. It has two ways to be used. Either an item in the array is a custom tag such as "!Ref" and it will automatically map !Ref to scalar or you can specify the type of the object !Ref should be e.g. "!Ref sequence". The type of object can be either scalar (for strings and booleans), sequence (for arrays), map (for objects).
4040
* `[yaml]`: VSCode-YAML adds default configuration for all yaml files. More specifically it converts tabs to spaces to ensure valid yaml, sets the tab size, and allows live typing autocompletion. These settings can be modified via the corresponding settings inside the `[yaml]` section in the settings:
4141
* `editor.insertSpaces`
4242
* `editor.tabSize`
4343
* `editor.quickSuggestions`
4444

45+
##### Adding custom tags
46+
47+
In order to use the custom tags in your YAML file you need to first specify the custom tags in the setting of your code editor. For example, we can have the following custom tags:
48+
49+
```YAML
50+
"yaml.customTags": [
51+
"!Scalar-example scalar",
52+
"!Seq-example sequence",
53+
"!Mapping-example mapping"
54+
]
55+
```
56+
57+
The !Scalar-example would map to a scalar custom tag, the !Seq-example would map to a sequence custom tag, the !Mapping-example would map to a mapping custom tag.
58+
59+
We can then use the newly defined custom tags inside our YAML file:
60+
61+
```YAML
62+
some_key: !Scalar-example some_value
63+
some_sequence: !Seq-example
64+
- some_seq_key_1: some_seq_value_1
65+
- some_seq_key_2: some_seq_value_2
66+
some_mapping: !Mapping-example
67+
some_mapping_key_1: some_mapping_value_1
68+
some_mapping_key_2: some_mapping_value_2
69+
```
70+
4571
##### Associating a schema to a glob pattern via yaml.schemas:
4672
yaml.schemas applies a schema to a file. In other words, the schema (placed on the left) is applied to the glob pattern on the right. Your schema can be local or online. Your schema must be a relative path and not an absolute path.
4773

0 commit comments

Comments
 (0)