Skip to content

Getting jQuery bundle to work within script tags embedded in HTML

kswedberg edited this page Sep 13, 2010 · 1 revision

Go to the Language item in the HTML bundle and add this to the top-level patterns object:

{	name = 'source.js.jquery.embedded.html';
			begin = '(?:^\s+)?(<)((?i:script))\b(?![^>]*/>)';
			end = '(?<=</(script|SCRIPT))(>)(?:\s*\n)?';
			beginCaptures = {
				1 = { name = 'punctuation.definition.tag.html'; };
				2 = { name = 'entity.name.tag.script.html'; };
			};
			endCaptures = { 2 = { name = 'punctuation.definition.tag.html'; }; };
			patterns = (
				{	include = '#tag-stuff'; },
				{	begin = '(?<!</(?:script|SCRIPT))(>)';
					end = '(</)((?i:script))';
					captures = {
						1 = { name = 'punctuation.definition.tag.html'; };
						2 = { name = 'entity.name.tag.script.html'; };
					};
					patterns = (
						{	name = 'comment.line.double-slash.js';
							match = '(//).*?((?=</script)|$\n?)';
							captures = { 1 = { name = 'punctuation.definition.comment.js'; }; };
						},
						{	name = 'comment.block.js';
							begin = '/\*';
							end = '\*/|(?=</script)';
							captures = { 0 = { name = 'punctuation.definition.comment.js'; }; };
						},
						{	include = '#php'; },
						{	include = 'source.js'; },
					);
				},
			);
		},