Skip to content

Commit

Permalink
Declare xml.colors settings
Browse files Browse the repository at this point in the history
See eclipse/lemminx#639

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed Jan 5, 2023
1 parent 57971ff commit c34d20d
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This VS Code extension provides support for creating and editing XML documents,
| enabled by default | requires additional configuration to enable |

- * [XML References features](https://github.com/redhat-developer/vscode-xml/blob/main/docs/Features/XMLReferencesFeatures.md#xml-references-features) (since v0.24.0)
- * [XML Colors features](https://github.com/redhat-developer/vscode-xml/blob/main/docs/Features/XMLColorsFeatures.md#xml-colors-features) (since v0.24.0)
* [RelaxNG (experimental) support](https://github.com/redhat-developer/vscode-xml/blob/main/docs/Features/RelaxNGFeatures.md#relaxng-features) (since v0.22.0)
* [Surround with Tags, Comments, CDATA](https://github.com/redhat-developer/vscode-xml/blob/main/docs/Refactor.md#refactor) (since v0.23.0)
* Syntax error reporting
Expand Down
3 changes: 2 additions & 1 deletion docs/Features.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
- [RelaxNG features](Features/RelaxNGFeatures.md#relaxng-features)
- [XInclude features](Features/XIncludeFeatures.md#xinclude-features)
- [XML Catalog features](Features/XMLCatalogFeatures.md#xml-catalog-features)
- [XML References features](Features/XMLReferencesFeatures.md#xml-references-features)
- [XML References features](Features/XMLReferencesFeatures.md#xml-references-features)
- [XML Colors features](Features/XMLReferencesFeatures.md#xml-colors-features)
70 changes: 70 additions & 0 deletions docs/Features/XMLColorsFeatures.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# XML Colors Features

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 :

* `color/text()` defines the text node of the `color` element.
* `item/@color` defines the `color` attribute node of the `item` element.

## Define Color in Text Content with `color/text()`

Given this [android color](https://developer.android.com/guide/topics/resources/more-resources#Color) XML file sample:

```xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="opaque_red">#f00</color>
<color name="translucent_red">rgb(222,82,0.82)</color>
<drawable name="notification_template_icon_low_bg">#0cffffff</drawable>
</resources>
```

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:

```json
"xml.colors": [
{
"pattern": "**/res/values/colors.xml",
"expressions": [
{
"xpath": "resources/color/text()"
},
{
"xpath": "resources/drawable/text()"
}
]
}
]
```

After saving this setting, you will get color support for text node of `color` in the `colors.xml` file:

![XML Colors](../images/Features/XMLColorsFeatures.png)

## Define Color in Attribute with `item/@color`

Attribute values may also be marked as color by using the proper XPath.

Given this `colors.xml` XML file:

```xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item color="#f00" />
<item color="rgb(222,82,0.82)" />
</resources>
```

You can declare this settings:

```json
"xml.colors": [
{
"pattern": "**/colors.xml",
"expressions": [
{
"xpath": "item/@color"
}
]
}
]
```
2 changes: 1 addition & 1 deletion docs/Features/XMLReferencesFeatures.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# XML References Features

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 :
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 :

* `foo/@attr` defines the `attr` attribute node of the `foo` element.
* `foo/text()` defines the text node of the `foo` element.
Expand Down
Binary file added docs/images/Features/XMLColorsFeatures.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 36 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,42 @@
"expressions"
]
},
"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```",
"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.",
"scope": "window"
},
"xml.colors": {
"type": "array",
"default": [],
"items": {
"type": "object",
"properties": {
"pattern": {
"type": "string",
"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"
},
"expressions": {
"type": "array",
"default": [],
"items": {
"type": "object",
"properties": {
"xpath": {
"type": "string",
"description": "The color DOM node (attribute, text) declared with XPath (ex: foo/@color, foo/text())"
}
}
},
"required": [
"xpath"
]
}
},
"required": [
"pattern",
"expressions"
]
},
"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.",
"scope": "window"
},
"xml.extension.jars": {
Expand Down

0 comments on commit c34d20d

Please sign in to comment.