Sublime color scheme for XML with Unicode node name

4.6k Views Asked by At

If I use node name in ASCII, I have a nice view:

enter image description here

but if I use Unicode node name it is not pretty:

enter image description here

How can I fix this?

1

There are 1 best solutions below

0
On BEST ANSWER

Background

The XML syntax highlighting language definition that ships with Sublime Text 2/3 does not recognize non-ASCII tags:

Note: The Neon Color Scheme is used for syntax highlighting

original

However, replacing it with the file in this gist fixes that problem, along with a few minor things:

new


How to install

Sublime Text 2

In Sublime, open a new file and paste in the contents of the gist. Save the file to your Desktop as XML.tmLanguage. Open your Packages folder by selecting Preferences → Browse Packages…, then close Sublime. Scroll down to the XML folder and rename XML.tmLanguage as XML.tmLanguage.old. If it exists, delete XML.tmLanguage.cache. Now, copy the new XML.tmLanguage from your Desktop to Packages/XML. The next time you open an XML file in Sublime, it will use the new syntax.

Sublime Text 3 Build <= 3083 (public beta)

In Sublime, open a new file and paste in the contents of the gist. Save the file to your Desktop as XML.tmLanguage. Open your Packages folder by selecting Preferences → Browse Packages…, then close Sublime. Create a new folder in Packages named XML and copy the new XML.tmLanguage from your Desktop to Packages/XML. The next time you open an XML file in Sublime, it will use the new syntax.

Sublime Text 3 Build > 3083 (dev builds)

In Sublime, open a new file and paste in the contents of the gist. Save the file to your Desktop as XML.tmLanguage. Create another new file in Sublime with the following contents:

%YAML 1.2
---
name: XML-ss
file_extensions:
first_line_match: '^<\?xml '
scope: text.xml
contexts:
  main:
    - match: ''
---

Save this file to your Desktop as XML.sublime-syntax. Open your Packages folder by selecting Preferences → Browse Packages…, then close Sublime. Create a new folder in Packages named XML and copy the new XML.tmLanguage and XML.sublime-syntax files from your Desktop to Packages/XML. The next time you open an XML file in Sublime, it will use the new syntax. There will be a new entry in the syntax menu called XML-ss (for sublime-syntax), just ignore it.


How it works

Sublime Text 2

Here, we simply replace the old language definition (.tmLanguage file) with the new one.

Sublime Text 3

In Sublime Text 3, the default packages (and many that you install with Package Control) are stored in a separate directory as zipped .sublime-package files. However, if you create a folder and file in the Packages folder with the same name as a package (XML in this case) and file contained within it, the version in Packages will override the version in the sublime-package archive. For ST3 builds 3083 and before, the same XML-based .tmLanguage format as ST2 was used.

However, starting with dev build 3084 and beyond, a new YAML-based .sublime-syntax format was introduced, and all of the default syntax definitions were converted. The .tmLanguage format is still supported, however, but we needed to override the XML/XML.sublime-syntax file first in order for our new .tmLanguage file to be used.