|
| 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 | + |
| 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 | +``` |
0 commit comments