Skip to content

Commit b338c32

Browse files
angelozerrdatho7561
authored andcommitted
Declare xml.colors settings
See eclipse-lemminx/lemminx#639 Signed-off-by: azerr <[email protected]>
1 parent 57971ff commit b338c32

File tree

6 files changed

+110
-3
lines changed

6 files changed

+110
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This VS Code extension provides support for creating and editing XML documents,
2020
| enabled by default | requires additional configuration to enable |
2121

2222
- * [XML References features](https://github.com/redhat-developer/vscode-xml/blob/main/docs/Features/XMLReferencesFeatures.md#xml-references-features) (since v0.24.0)
23+
- * [XML Colors features](https://github.com/redhat-developer/vscode-xml/blob/main/docs/Features/XMLColorsFeatures.md#xml-colors-features) (since v0.24.0)
2324
* [RelaxNG (experimental) support](https://github.com/redhat-developer/vscode-xml/blob/main/docs/Features/RelaxNGFeatures.md#relaxng-features) (since v0.22.0)
2425
* [Surround with Tags, Comments, CDATA](https://github.com/redhat-developer/vscode-xml/blob/main/docs/Refactor.md#refactor) (since v0.23.0)
2526
* Syntax error reporting

docs/Features.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
- [RelaxNG features](Features/RelaxNGFeatures.md#relaxng-features)
99
- [XInclude features](Features/XIncludeFeatures.md#xinclude-features)
1010
- [XML Catalog features](Features/XMLCatalogFeatures.md#xml-catalog-features)
11-
- [XML References features](Features/XMLReferencesFeatures.md#xml-references-features)
11+
- [XML References features](Features/XMLReferencesFeatures.md#xml-references-features)
12+
- [XML Colors features](Features/XMLColorsFeatures.md#xml-colors-features)

docs/Features/XMLColorsFeatures.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# XML Colors Features
2+
3+
XML colors support provides the capability to mark a DOM node (attribute or text) as color with the `xml.colors` settings by using XPath expression :
4+
5+
* `color/text()` defines the text node of the `color` element.
6+
* `item/@color` defines the `color` attribute node of the `item` element.
7+
8+
## Define Color in Text Content with `color/text()`
9+
10+
Given this [android color](https://developer.android.com/guide/topics/resources/more-resources#Color) XML file sample:
11+
12+
```xml
13+
<?xml version="1.0" encoding="utf-8"?>
14+
<resources>
15+
<color name="opaque_red">#f00</color>
16+
<color name="translucent_red">rgb(222,82,0.82)</color>
17+
<drawable name="notification_template_icon_low_bg">#0cffffff</drawable>
18+
</resources>
19+
```
20+
21+
In this sample, text of `color` tag element `<color name="opaque_red">#f00</color>` declare a color with hexadecimal. [vscode-xml](https://github.com/redhat-developer/vscode-xml) provides a color support with the `xml.colors` settings. For [android color](https://developer.android.com/guide/topics/resources/more-resources#Color) case, you can declare this settings:
22+
23+
```json
24+
"xml.colors": [
25+
{
26+
"pattern": "**/res/values/colors.xml",
27+
"expressions": [
28+
{
29+
"xpath": "resources/color/text()"
30+
},
31+
{
32+
"xpath": "resources/drawable/text()"
33+
}
34+
]
35+
}
36+
]
37+
```
38+
39+
After saving this setting, you will get color support for the text node of `color` tag element in the `colors.xml` file:
40+
41+
![XML Colors](../images/Features/XMLColorsFeatures.png)
42+
43+
## Define Color in Attribute with `item/@color`
44+
45+
Attribute values may also be marked as color by using the proper XPath.
46+
47+
Given this `colors.xml` XML file:
48+
49+
```xml
50+
<?xml version="1.0" encoding="utf-8"?>
51+
<resources>
52+
<item color="#f00" />
53+
<item color="rgb(222,82,0.82)" />
54+
</resources>
55+
```
56+
57+
You can declare this settings:
58+
59+
```json
60+
"xml.colors": [
61+
{
62+
"pattern": "**/colors.xml",
63+
"expressions": [
64+
{
65+
"xpath": "item/@color"
66+
}
67+
]
68+
}
69+
]
70+
```

docs/Features/XMLReferencesFeatures.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# XML References Features
22

3-
XML References support provides the capability to reference a DOM node (attribute or text) to an another DOM node (attribute or text) with a the `xml.references` settings by using XPath expression :
3+
XML References support provides the capability to reference a DOM node (attribute or text) to an another DOM node (attribute or text) with the `xml.references` settings by using XPath expression :
44

55
* `foo/@attr` defines the `attr` attribute node of the `foo` element.
66
* `foo/text()` defines the text node of the `foo` element.
57.5 KB
Loading

package.json

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,42 @@
674674
"expressions"
675675
]
676676
},
677-
"markdownDescription": "Allows XML schemas/ DTD to be associated to file name patterns. Please refer to [XML file association with XSD](command:xml.open.docs?%5B%7B%22page%22%3A%22Validation%22%2C%22section%22%3A%22xml-file-association-with-xsd%22%7D%5D) or [XML file association with DTD](command:xml.open.docs?%5B%7B%22page%22%3A%22Validation%22%2C%22section%22%3A%22xml-file-association-with-dtd%22%7D%5D) for more information. \n\nExample:\n```json\n[{\n \"pattern\": \"file1.xml\",\n \"systemId\": \"path/to/file.xsd\"\n},\n{\n \"pattern\": \"**/*.xsd\",\n \"systemId\": \"http://www.w3.org/2001/XMLSchema.xsd\"\n}]\n```",
677+
"markdownDescription": "Allows references for the given file name patterns. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Features/XMLReferencesFeatures%22%2C%22section%22%3A%22xmlreferencesfeatures%22%7D%5D) for more information.",
678+
"scope": "window"
679+
},
680+
"xml.colors": {
681+
"type": "array",
682+
"default": [],
683+
"items": {
684+
"type": "object",
685+
"properties": {
686+
"pattern": {
687+
"type": "string",
688+
"markdownDescription": "matches the files that colors declared with `expressions` applies to.\n\nMore information on the glob syntax: https://docs.oracle.com/javase/tutorial/essential/io/fileOps.html#glob"
689+
},
690+
"expressions": {
691+
"type": "array",
692+
"default": [],
693+
"items": {
694+
"type": "object",
695+
"properties": {
696+
"xpath": {
697+
"type": "string",
698+
"description": "The color DOM node (attribute, text) declared with XPath (ex: foo/@color, foo/text())"
699+
}
700+
}
701+
},
702+
"required": [
703+
"xpath"
704+
]
705+
}
706+
},
707+
"required": [
708+
"pattern",
709+
"expressions"
710+
]
711+
},
712+
"markdownDescription": "Allows colors for the given file name patterns. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Features/XMLColorsFeatures%22%2C%22section%22%3A%22xmlcolorsfeatures%22%7D%5D) for more information.",
678713
"scope": "window"
679714
},
680715
"xml.extension.jars": {

0 commit comments

Comments
 (0)