I am trying to make sure that HTML code inside a PHP file is correctly highlighted, but is unsure about how to do it.
Example:
<?php function PrintHtml( ) { ?> <!-- HTML ONLY AREA --> <p>This is HTML</p> <?php } ?>
I understand that the syntax is as follows, but I don't know what the 'begin' and 'end' tags should be.
name = "Embedded HTML"; begin = "???????????"; end = "??????????????"; patterns = ( { include = "HTML"; } );
If anyone can help, I'd be grateful.
Kind regards,
Mats
On 13 Oct 2004, at 19:53, Mats Persson wrote:
I am trying to make sure that HTML code inside a PHP file is correctly highlighted, but is unsure about how to do it.
Umm, so what's wrong with the HTML-PHP syntax highlighting that ships with TM? Using this syntax, anything outside PHP delimiters is considered HTML and highlighted accordingly (albeit in grey), which is what you want, right?
Rich Barton
On 14/10-2004, at 0:14, Rich Barton wrote:
On 13 Oct 2004, at 19:53, Mats Persson wrote:
I am trying to make sure that HTML code inside a PHP file is correctly highlighted, but is unsure about how to do it.
Umm, so what's wrong with the HTML-PHP syntax highlighting that ships with TM? Using this syntax, anything outside PHP delimiters is considered HTML and highlighted accordingly (albeit in grey), which is what you want, right?
I also think it's best to do PHP inside HTML instead of the other way around, since HTML isn't really imbedded into PHP but rather vice versa. In the future Syntax Highlight system there should be plenty of possibilities for highlight that changes with context (so HTML is gray when in PHP and vice versa) and other nifty things :-).
Hi Rich & Sune,
Umm, so what's wrong with the HTML-PHP syntax highlighting that ships with TM? Using this syntax, anything outside PHP delimiters is considered HTML and highlighted accordingly (albeit in grey), which is what you want, right?
Perhaps I didn't make myself clear enough, so let's use some images to save me a 1000 words. ; )
in BBEdit 8.0
in skEdit 3.5b5 with PHP syntax highlighting
in TextMate with 'HTML (Basic)' syntax highlighting
in TextMate with 'HTML (PHP)' syntax highlighting
in TextMate with 'PHP' syntax highlighting: (HTML treated as PHP code)
What I would like is something along the lines of BBEdit & skEdit's and their dual highlighting capabilities. In other words, when we are in a .php file and exit php with ?> and then start having HTML code in there, then the HTML code highlighting should work just as IF we were using a .html file. And vice versa.
As it is right now, I have a choice of highlighting for HTML or for PHP, BUT NOT both at the same time.
All my settings and the results thereof:
My HTML syntax file is in a bundle called mxHTML and the syntax file is named mxHTML.plist and it is a copy of this file:
BASIC HTML DICTIONARY FOR TEXTMATE ================================== Version 1.0 (Sune Foldager, Justin French, Allan Odgaard)
with the following changes (apart from colour settings):
name = "mxHTML";
/* * embedded languages -- [SNIP] */ { name = "Embedded PHP"; begin = "<\?(php|=)?"; end = "\?>"; patterns = ( { include = "mxPHP"; } ); },
My PHP syntax file is in a bundle called mxPHP and the syntax file is named mxPHP.plist and its a copy of Jason Spahr's Smarty PHP bundle.
with the following changes:
name = "mxPHP";
{ name = "Embedded HTML"; begin = "\?>"; end = "<\?(php|=)?"; patterns = ( { include = "mxHTML"; } ); },
The same code block rendered with my syntax files:
with mxHTML syntax highlighting:
with mxPHP syntax highlighting:
Apologies for the length and size of this email, but I hope this will have clarified my position and aid in solving this problem.
IF I am asking for the impossible, then Allan & gang has some more work to do, else I am doing something wrong, and someone smarter than me will hopefully point me in the right direction. : )
Kind regards,
Mats
On 14. Oct 2004, at 12:40, Mats Persson wrote:
What I would like is something along the lines of BBEdit & skEdit's and their dual highlighting capabilities. In other words, when we are in a .php file and exit php with ?> and then start having HTML code in there, then the HTML code highlighting should work just as IF we were using a .html file. And vice versa.
As it is right now, I have a choice of highlighting for HTML or for PHP, BUT NOT both at the same time.
No, the "HTML (PHP)" does do this. But the colors of HTML is toned down significantly.
with the following changes:
name = "mxPHP";
{ name = "Embedded HTML"; begin = "\?>"; end = "<\?(php|=)?"; patterns = ( { include = "mxHTML"; } ); },
But as Sune said, HTML is not embedded in the file. HTML _is_ the file.
So either make the mxHTML include mxPHP or do a "wrapper" for both like this:
name = "mxHTML + PHP"; ... patterns = (
{ name = "Embedded PHP"; begin = "<\?(php|=)?"; end = "\?>"; patterns = ( { include = "mxPHP"; } ); },
{ include = "mxHTML"; }
);
This will use the mxPHP patterhs for everything inside the PHP tags, and for the rest, it'll use the mxHTML patterns.
I didn't test this, but it I think it should work. However, the wrapper is sort of redundant, unless you want to re-use the mxHTML patterns without the PHP inclusion.
Kind regards Allan
Allan,
Thank you for your help !!! Very much appreciated.
As it is right now, I have a choice of highlighting for HTML or for PHP, BUT NOT both at the same time.
No, the "HTML (PHP)" does do this. But the colors of HTML is toned down significantly.
Ahh, the perils of editing syntax files without understanding things fully. I made a colour change to the "HTML (PHP)" syntax file and stored it in the AppSupport directory, so it overrode your file, and in doing so it created plain black text on white background. : (
I have now spent a good few hours tweaking my colours and have HTML with PHP; with CSS; with JS highlighting working just as I want it.
Although time consuming, it has been a very good process to go through, and I have learnt a lot about the syntax structure. As a result, I am very impressed by the inherent power in the syntax format.
My only concern now - as I have migrated to a dark background - is that the cursor is invisible over the edit window. Perhaps something that you are already aware of and working on. (Or perhaps is remedied by some to me unknown setting).
Kind regards,
Mats
On 14. Oct 2004, at 18:37, Mats Persson wrote:
My only concern now - as I have migrated to a dark background - is that the cursor is invisible over the edit window. Perhaps something that you are already aware of and working on. (Or perhaps is remedied by some to me unknown setting).
Yes, Justin just sent me a few I-beam cursors that I hope will make it to beta 4 (which should be out later today (and it's 19:30 currently)).
Kind regards Allan
Mats,
If you got the HTML/PHP syntax highlighting working like you explained, could you make the .tmbundle file available? I can't stand the light HTML with bright PHP etc.
-Noel
On Oct 14, 2004, at 12:37 PM, Mats Persson wrote:
Allan,
Thank you for your help !!! Very much appreciated.
As it is right now, I have a choice of highlighting for HTML or for PHP, BUT NOT both at the same time.
No, the "HTML (PHP)" does do this. But the colors of HTML is toned down significantly.
Ahh, the perils of editing syntax files without understanding things fully. I made a colour change to the "HTML (PHP)" syntax file and stored it in the AppSupport directory, so it overrode your file, and in doing so it created plain black text on white background. : (
I have now spent a good few hours tweaking my colours and have HTML with PHP; with CSS; with JS highlighting working just as I want it.
Although time consuming, it has been a very good process to go through, and I have learnt a lot about the syntax structure. As a result, I am very impressed by the inherent power in the syntax format.
My only concern now - as I have migrated to a dark background - is that the cursor is invisible over the edit window. Perhaps something that you are already aware of and working on. (Or perhaps is remedied by some to me unknown setting).
Kind regards,
Mats
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/mailman/listinfo/textmate
---------------------- noel@noeljackson.com http://noeljackson.com http://relevantly.com ----------------------
I would like snippets to be able to be activated by a modifier key...
For example say I've got a snippet like this... <h1>${1:`echo $TM_SELECTED_TEXT`}</h1>$0
I'd like to be able to assign ⌥⌘1 to this snippet. Instead of the h1[tab], which wouldn't allow me to use the snippet to it's full ability.
Noel,
You can always record a macro that invokes your snippet and bind a key to invoke the macro. Yeah, it's a bit more work but not much. I wrote an example on how to use snippets and macros effectively together (http://jlaine.net/blog/10/textmate-goodie-1) and I remember someone had already earlier done something similar for HTML tags.
//jarkko
On 14.10.2004, at 21:42, Noel D.Jackson wrote:
I would like snippets to be able to be activated by a modifier key...
For example say I've got a snippet like this... <h1>${1:`echo $TM_SELECTED_TEXT`}</h1>$0
I'd like to be able to assign ⌥⌘1 to this snippet. Instead of the h1[tab], which wouldn't allow me to use the snippet to it's full ability._______________________________________________ textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/mailman/listinfo/textmate
-- Jarkko Laine http://jlaine.net
On 14. Oct 2004, at 20:42, Noel D.Jackson wrote:
I would like snippets to be able to be activated by a modifier key...
Yeah, I figured I should do this for no other reason than just for completeness sake ;)
I'll do it whenever I find a free moment!
Kind regards Allan
Awesome!
On Oct 14, 2004, at 3:00 PM, Allan Odgaard wrote:
On 14. Oct 2004, at 20:42, Noel D.Jackson wrote:
I would like snippets to be able to be activated by a modifier key...
Yeah, I figured I should do this for no other reason than just for completeness sake ;)
I'll do it whenever I find a free moment!
Kind regards Allan
---------------------- noel@noeljackson.com http://noeljackson.com http://relevantly.com ----------------------
Mats,
If you got the HTML/PHP syntax highlighting working like you explained, could you make the .tmbundle file available? I can't stand the light HTML with bright PHP etc.
-Noel
Sure will do. Let me clear up some of the remaining issues with JavaScript colouring which I'm not too happy with.
Will write a test case file tomorrow that will contain all the various parts - completely embedded within each other - so that a single screenshot can show all the colours used.
Noel, If you wish to help with it, please have a go at the bundle sent OFF-List to you.
Anyone else, please be patient for a few days, and I will make them available on the wiki. (Them = Dark & White versions )
Kind regards,
Mats
-- -- -- -- -- "For those who aren't familiar with OS X, it is a full implementation of BSD Unix with a Macintosh front end, which is to say world class inside and out. OS X is faster, smarter, prettier, and easier to use than any version of Windows." by Robert X. Cringley, Feb, 2002 [ http://www.pbs.org/cringely/ ]