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 &开发者_StackOverflow中文版lt;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.
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 = '\\[\\'']';
},
);
};
You would probably have to do some rather complicated editing of the scope definitions for HTML in order to get this to work as you describe. PHP files are HTML files by default in TextMate, so you're looking to define a scope where you have an HTML file with embedded PHP with strings that might be HTML. Not every string in PHP is going to be HTML, so you'd need to figure out a way to differentiate non-HTML strings from HTML strings, and if you're not fluent with regular expressions, it would probably take quite a bit of research and trial and error to get it right.
As an alternative, if you're actually using printf
rather than simply using it as a generic example, consider using the function to format only what you need formatted and doing something like this.
<?php
$var = sprintf( '%d', $num );
?>
Here's the <strong><?php echo $var; ?></strong>.
精彩评论