Sublime Forum

Color Scheme Help

#1

Hi All

I’m just starting to create my own color scheme for ST2 and I’ve come up against a slight problem. For markup languages I’m trying to color the attribute differently to the tag. Which I’ve done like this …

<dict>
			<key>name</key>
			<string>Tag Name</string>
			<key>scope</key>
			<string>entity.name.tag, meta.tag, declaration.tag</string>
			<key>settings</key>
			<dict>
				<key>foreground</key>
				<string>#32665F</string>
			</dict>
		</dict>
		<dict>
			<key>name</key>
			<string>Tag attribute</string>
			<key>scope</key>
			<string>entity.other.attribute-name</string>
			<key>settings</key>
			<dict>
				<key>foreground</key>
				<string>#64A59C</string>
			</dict>
		</dict>

However for something like

this colors the “=” equals sign the same color as the tag name and I’d like it to either be a different color altogether or the same color as the attribute.

Is there anyway I can set the color the equals sign specifically or make the same as the attribute and attribute value?

Many thanks

0 Likes

#2

Since the = does not have a scope explicitly set you have to do it the other way around or just exclude everything else.

For your snippet <table class="someClass"> with cursors ("|")here: |<tab|le cla|ss|="some|Class"> I get the following (I wrote a small plugin for that but Ctrl+Alt+Shift+P works as well here):

line 1, col 1: text.html.basic meta.tag.inline.any.html punctuation.definition.tag.begin.html line 1, col 5: text.html.basic meta.tag.inline.any.html entity.name.tag.inline.any.html line 1, col 11: text.html.basic meta.tag.inline.any.html entity.other.attribute-name.html line 1, col 13: text.html.basic meta.tag.inline.any.html line 1, col 19: text.html.basic meta.tag.inline.any.html string.quoted.double.html

and col 13 is what we want to highlight. As you can see, it is the shortest scope so you could address “meta.tag” directly and let the other tags override it (foreground color only!) This introduces a problem with the “punctuation” angle brackets because they don’t have another color assigned to them which leaves them with the same color as the “=”.

Solution: Do an opt-out selector. Using a selector like meta.tag - (entity, punctuation, string) we have essentially eliminated all the fuss about highlighting stuff we don’t want to highlight and are only left with our “=” and whitespaces (only visible when modifying the background color). And it will also highlight everything unquoted because the syntax definition does not take care of them (e.g. “”) but still, works fine most of the time.

Here is what my definition looks like (in YAML):

- name: Assignment "=" for HTML attributes scope: meta.tag.inline.any.html - (entity, punctuation, string) settings: foreground: '#3609C4'

I hope this isn’t too clustered to follow.

0 Likes

#3

Oh yeah! I got it working. It wasn’t that hard to follow, just takes a few tries though. Thank you so much for the help with this one!

0 Likes