Sublime Forum

Javascript Block Inside HTML -- Incorrect Color Coding

#1

Hi

This is the text block that I’m using for to illustrate the poing:

<html>
	<head>
		<script>
			var test = "blah";
		</script>
	</head>
	<body>
	</body>
</html>

Set the color scheme to Monokai.

You should see something like this: skitch.com/indiver/rur6e/incorr … ript-block

Or have a look at the attachment.

You’ll notice that the closing tag is not color coded correctly.

I’ve tried other color schemes as well, but the same issue. For any inline Javascript block, the closing script tag is not color coded correctly.

I discovered this issue in the ColdFusion color coding where a block would show the correct color. After looking at the language definition I found that it uses the inline Javascript (in HTML) code to render.

Can anything be done about it? It is not a biggie, but would be really nice to have a workaround or fix.

Thanks

Indy

0 Likes

#2

Anyone? Any thoughts on how to fix this?

0 Likes

#3

Hi again.

Problem lies in the Coldfusion.tmLanguage.
At line 262 you can replace with this:

				<key>begin</key>
				<string>(?:^\s+)?&lt;((?i:script))\b(?!^&gt;]*/&gt;)</string>
				<key>beginCaptures</key>
				<dict>
					<key>1</key>
					<dict>
						<key>name</key>
						<string>entity.name.tag.script.html</string>
					</dict>
				</dict>
				<key>end</key>
				<string>(?&lt;=&lt;/(script|SCRIPT))&gt;(?:\s*\n)?</string>
				<key>endCaptures</key>
				<dict>
					<key>1</key>
					<dict>
						<key>name</key>
						<string>entity.name.tag.script.html</string>
					</dict>
				</dict>
				<key>name</key>
				<string>source.js.embedded.html</string>

I haven’t tested this. In fact, there’s a lot in that tmLanguage that can be fixed up to work better with Sublime.
You could gut a lot of the html stuff and just add the following for all the html.

		<dict>
			<key>include</key>
			<string>text.html.basic</string>
		</dict>

It sounds like a fun project if you’re up for it.

0 Likes

#4

Thanks for that pointer. I had make a few other change as well. I’m going to be pushing the changes to the repo.

Yes, it is a worthwhile project, however, I know that alone it would be too difficult to find time. However, my hope is that as it is on GitHub, others can fork and make it better.

0 Likes

#5

The same thing occurs when you’ve got a structure of:

HTML -> Style Type = “text/css” -> PHP

ST must have a limit of how many styles it can highlight inside of each other.

0 Likes

#6

One can fix it changing the bundle to use the same code as the HTML bundle.

Have a look at github commit where I made that change.

github.com/indynagpal/coldfusio … d65c46358a

0 Likes