<?xml version="1.0"?>
<syntax name="language-root.html">
	<zones>
		<zone name="tag.preprocessor.xml.html">
			<starts-with>
				<expression>(&lt;\?)(xml)</expression>
				<capture number="1" name="punctuation.definition.begin"/>
				<capture number="2" name="entity.name"/>
			</starts-with>
			<ends-with>
				<expression>(\?>)</expression>
				<capture number="1" name="punctuation.definition.end"/>
			</ends-with>
			<subzones>
				<include collection="tag-attributes"/>
			</subzones>
		</zone>
		<zone name="comment.block.html.conditional">
			<starts-with>
				<expression>(?i)(&lt;!--)(\[(if [^\]]+)\]>(?:\s*&lt;!-->)?)</expression>
				<capture number="1" name="punctuation.definition.begin"/>
				<capture number="2" name="ie.conditional.start"/>
				<capture number="3" name="condition"/>
			</starts-with>
			<ends-with>
				<expression>(?i)((?:&lt;!--\s*)?&lt;!\[endif\])(-->)</expression>
				<capture number="1" name="ie.conditional.end"/>
				<capture number="2" name="punctuation.definition.end"/>
			</ends-with>
			<subzones>
				<cut-off>(?i)(?:&lt;!--\s*)?&lt;!\[endif\]--></cut-off>
				<include syntax="language-root.html" />
			</subzones>
		</zone>
		<zone name="comment.block.html">
			<starts-with>
				<expression>&lt;!--</expression>
				<capture number="0" name="punctuation.definition.begin"/>
			</starts-with>
			<ends-with>
				<expression>--></expression>
				<capture number="0" name="punctuation.definition.end"/>
			</ends-with>
			<subzones>
				<zone name="invalid.illegal.bad-comments-or-CDATA.html">
					<expression>--(?!>|->)</expression>
				</zone>
			</subzones>
		</zone>
		<zone name="tag.doctype.html">
			<starts-with>
				<expression>(&lt;!)(?i:DOCTYPE)</expression>
				<capture number="1" name="punctuation.definition.begin"/>
				<capture number="2" name="entity.name"/>
			</starts-with>
			<ends-with>
				<expression>></expression>
				<capture number="0" name="punctuation.definition.end"/>
			</ends-with>
		</zone>
		<zone name="tag.self-closing.cdata.html">
			<starts-with>
				<expression>&lt;!\[CDATA\[</expression>
				<capture number="0" name="punctuation.definition"/>
			</starts-with>
			<ends-with>
				<expression>\]\]></expression>
				<capture number="0" name="punctuation.definition"/>
			</ends-with>
		</zone>
        
        <!-- Embedded styles -->
		<zone name="embedded-style.html">
			<starts-with>
				<expression>(?=&lt;(?i:style))</expression>
			</starts-with>
			<ends-with>
				<expression>(&lt;/)((?i:style))(>)</expression>
				<capture number="0" name="tag.close.x-style.html"/>
				<capture number="1" name="punctuation.definition"/>
				<capture number="2" name="entity.name"/>
				<capture number="3" name="punctuation.definition"/>
			</ends-with>
			<subzones>
				<zone name="tag.open.x-style.html">
					<starts-with>
						<expression>(&lt;)((?i:style))</expression>
						<capture number="1" name="punctuation.definition.begin"/>
						<capture number="2" name="entity.name"/>
					</starts-with>
					<ends-with>
						<expression>></expression>
						<capture number="0" name="punctuation.definition.end"/>
					</ends-with>
					<subzones>
						<include collection="tag-attributes"/>
					</subzones>
				</zone>
				<zone name="embedded.language-root.css">
					<starts-with>
						<expression>(?&lt;=>)\s*(&lt;!--)?</expression>
						<capture number="1" name="comment.embedded"/>
					</starts-with>
					<ends-with>
						<expression>(-->\s*)?(?=&lt;/(?i:style)>)</expression>
						<capture number="1" name="comment.embedded"/>
					</ends-with>
					<subzones>
						<include syntax="language-root.css"/>
					</subzones>
				</zone>
				<!--<include syntax="language-root.css"/>-->
			</subzones>
		</zone>
        
        <!-- Embedded JavaScript block -->
		<zone name="embedded-javascript.html">
			<starts-with>
				<expression>(?=&lt;(?i:script))</expression>
			</starts-with>
			<ends-with>
				<expression>(&lt;/)((?i:script))(>)</expression>
				<capture number="0" name="tag.close.block.x-script.html"/>
				<capture number="1" name="punctuation.definition.begin"/>
				<capture number="2" name="entity.name"/>
				<capture number="3" name="punctuation.definition.end"/>
			</ends-with>
			<subzones>
				<zone name="tag.open.block.x-script.html">
					<starts-with>
						<expression>(&lt;)((?i:script))</expression>
						<capture number="1" name="punctuation.definition.begin"/>
						<capture number="2" name="entity.name"/>
					</starts-with>
					<ends-with>
						<expression>></expression>
						<capture number="0" name="punctuation.definition.end"/>
					</ends-with>
					<subzones>
						<include collection="tag-attributes"/>
					</subzones>
				</zone>
				<zone name="embedded.language-root.js">
					<starts-with>
						<expression>(?&lt;=>)\s*(&lt;!--)?</expression>
						<capture number="1" name="comment.embedded"/>
					</starts-with>
					<ends-with>
						<expression>((?://)?\s*(?:-->|]]&gt;)\s*)?(?=&lt;/(?i:script)>)</expression>
						<capture number="1" name="comment.embedded"/>
					</ends-with>
					<subzones>
						<include syntax="language-root.js"/>
					</subzones>
				</zone>
				<!--<include syntax="language-root.js"/>-->
			</subzones>
		</zone>
		
		<!-- This is only in a collection so that it can be pulled in by other languages -->
		<include collection="tags" />
		
		<include collection="entities"/>
		
		<zone>
			<expression>(&lt;>)|(&lt;)</expression>
			<capture number="1" name="invalid.illegal.incomplete.html"/>
			<capture number="2" name="invalid.illegal.bad-angle-bracket.html"/>
		</zone>
	</zones>
    
    <!-- Zone library -->
	<library>
		<collection name="tags">
		<!-- FIXME: Should I capture these instead of letting them get caught by "other"? "area, button, datalist, del, ins, optgroup, option, select, label, legend". Originally left them unaccounted for for formatting purposes, but the formatters do not need to care about this anymore. -->
			<zone name="tag.open.html">
				<starts-with>
					<expression>(&lt;)([a-zA-Z:_]+[a-zA-Z:_0-9.-]*)</expression>
					<capture number="1" name="punctuation.definition.begin"/>
					<capture number="2" name="entity.name" behavior="text-to-parent-name" behavior-match="^(?:(address|article|aside|audio|blockquote|body|canvas|caption|center|colgroup|dd|details|dir|div|dl|dt|embed|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hgroup|html|iframe|li|map|menu|nav|noframes|noscript|object|ol|output|p|pre|progress|samp|section|table|tbody|td|textarea|tfoot|th|thead|title|tr|ul|video)|(a|abbr|acronym|b|big|cite|code|dfn|command|em|font|i|kbd|mark|meter|q|s|small|span|strike|strong|sub|summary|sup|time|tt|u|var)|(base|basefont|img|br|link|meta|hr|input|command|col|wbr|source|track)|(.*))$" behavior-transform="(?1:block:)(?2:inline:)(?3:self-closing:)(?4:other:).x-$0" />
				</starts-with>
				<ends-with>
					<expression>(/?>)</expression>
					<capture number="1" name="punctuation.definition.end" behavior="text-to-name" behavior-match="^(/)>$" behavior-transform="(?1:self-closing:)" />
				</ends-with>
				<subzones>
					<include collection="tag-attributes"/>
				</subzones>
			</zone>
			<zone name="tag.close.html">
				<starts-with>
					<expression>(&lt;/)([a-zA-Z:_]+[a-zA-Z:_0-9.-]*)</expression>
					<capture number="1" name="punctuation.definition.begin"/>
					<capture number="2" name="entity.name" behavior="text-to-parent-name" behavior-match="^(?:(address|article|aside|audio|blockquote|body|canvas|caption|center|colgroup|dd|details|dir|div|dl|dt|embed|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hgroup|html|iframe|li|map|menu|nav|noframes|noscript|object|ol|output|p|pre|progress|samp|section|table|tbody|td|textarea|tfoot|th|thead|title|tr|ul|video)|(a|abbr|acronym|b|big|cite|code|dfn|command|em|font|i|kbd|mark|meter|q|s|small|span|strike|strong|sub|summary|sup|time|tt|u|var)|(base|basefont|img|br|link|meta|hr|input|command|col|wbr|source|track)|(.*))$" behavior-transform="(?1:block:)(?2:inline:)(?3:self-closing:)(?4:other:).x-$0" />
				</starts-with>
				<ends-with>
					<expression>(>)</expression>
					<capture number="1" name="punctuation.definition.end"/>
				</ends-with>
			</zone>
		</collection>
		<collection name="entities">
			<zone>
				<expression>((&amp;)(?:[a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA-F]+)(;))|(&amp;)</expression>
				<!-- &entity; -->
				<capture number="1" name="constant.character.entity.html"/>
				<capture number="2" name="punctuation.definition.entity.html"/>
				<capture number="3" name="punctuation.definition.entity.html"/>
				<!-- & -->
				<capture number="4" name="invalid.illegal.bad-ampersand.html"/>
			</zone>
		</collection>
		<collection name="tag-attributes">
			<!--Attributes-->
			<zone>
				<expression>\s+(style)(=)((")([^"]*)(")|(')([^']*)('))|\s+(on[a-zA-Z]+)(=)((")(.*?)((?&lt;!\\)")|(')(.*?)((?&lt;!\\)'))|\s+([-_a-zA-Z0-9:]+)(=)</expression>
				<!-- Embedded CSS -->
				<capture number="1" name="attribute-name.x-style"/>
				<capture number="2" name="punctuation.separator.attribute"/>
				<capture number="3" name="string.quoted"/>
				<capture number="4" name="punctuation.definition.begin"/>
				<capture number="5" name="embedded.property-list.css">
					<subzones>
						<include syntax="language-root.css" collection="properties"/>
					</subzones>
				</capture>
				<capture number="6" name="punctuation.definition.end"/>
				<!-- Single-quoted strings -->
				<capture number="7" name="punctuation.definition.begin"/>
				<capture number="8" name="embedded.property-list.css">
					<subzones>
						<include syntax="language-root.css" collection="properties"/>
					</subzones>
				</capture>
				<capture number="9" name="punctuation.definition.end"/>
				<!-- Embedded JS -->
				<capture number="10" name="attribute-name.x-js"/>
				<capture number="11" name="punctuation.separator.attribute"/>
				<capture number="12" name="string.quoted"/>
				<capture number="13" name="punctuation.definition.begin"/>
				<capture number="14" name="embedded.sourcecode.js">
					<subzones>
						<include syntax="language-root.js"/>
					</subzones>
				</capture>
				<capture number="15" name="punctuation.definition.end"/>
				<!-- Single-quoted strings -->
				<capture number="16" name="punctuation.definition.begin"/>
				<capture number="17" name="embedded.sourcecode.js">
					<subzones>
						<include syntax="language-root.js"/>
					</subzones>
				</capture>
				<capture number="18" name="punctuation.definition.end"/>
				<!-- Generic attributes -->
				<capture number="19" name="attribute-name">
					<subzones>
						<zone>
							<expression>([^:]+)(:)(.*)</expression>
							<capture number="1" name="namespace"/>
							<capture number="2" name="punctuation.separator"/>
							<capture number="3" name="localname"/>
						</zone>
					</subzones>
				</capture>
				<capture number="20" name="punctuation.separator.attribute"/>
			</zone>
            <include collection="strings"/>
        </collection>
		
        <collection name="strings">
            <zone name="attribute-value.string.quoted">
                <starts-with>
                    <expression>("|')</expression>
                    <capture number="0" name="punctuation.definition.begin"/>
                </starts-with>
                <ends-with>
                    <expression>\1</expression>
                    <capture number="0" name="punctuation.definition.end"/>
                </ends-with>
				<subzones name="attribute-value.value" />
            </zone>
        </collection>
	</library>
</syntax>
