Search code examples
phphtmlsyntaxscopetextmate

Textmate: HTML syntax: embedded in PHP single and double quotes


Is there anyway to highlight HTML embedded in PHP single and double quotes — which has no scope defined, within Textmate?

Example:

printf( 'This is some <strong>Text</strong>', 'foobar' );

Everything within the single quotes belong to the same scope. Its annoying. Has anyone tried to fix this somehow? I'd rather not alter the language files (without guidance), im not fluent in regex.


Solution

  • Nevermind, i found out how to do it. After reading on how scopes work in Textmate. I opened up the PHP languages panel under the Bundle Editor and pasted an include of the following scope name into the string-single-quoted scope:

    text.html.basic

    Heres the include:

    { include = 'text.html.basic'; },

    and heres how the entire string-single-quoted section looks like now:

    string-single-quoted = {
            name = 'string.quoted.single.php';
            contentName = 'meta.string-contents.quoted.single.php';
            begin = "'";
            end = "'";
            beginCaptures = { 0 = { name = 'punctuation.definition.string.begin.php'; }; };
            endCaptures = { 0 = { name = 'punctuation.definition.string.end.php'; }; };
            patterns = (
                {   include = 'text.html.basic'; },
                {   name = 'constant.character.escape.php';
                    match = '\\[\\'']';
                },
            );
        };