Multi-language syntax highlighting for HTML files

Syntax highlighting, code folding, brace matching, code indenting, and function list

Multi-language syntax highlighting for HTML files

Postby THEMike » Tue Feb 08, 2005 6:19 am

I'm confused, and can't get this to work how I would expect/like:

IDM wrote:UE v11.00 has improved syntax highlighting and it now supports multiple languages within a single file. This is specifically for HTML type files. To help facilitate this, we have added additional language indicators that should be added to the wordfile.txt file to indicate the type of language for any languages that may be included within another. Our default wordfile has these modifications.

Example:

If an HTML file includes PHP then the syntax highlighting section must exist in the main wordfile and the PHP section should include in the definition line: PHP_LANG

Currently, UE uses the above language markers to correctly syntax highlight multiple languages within a file. In the future UE may make further use of these languages markers in the Wordfile.

So, I'm expecting that with the default wordfile.txt shipped with UltraEdit 11.00 that the PHP code will be formatted as per the section defined as:

Code: Select all
/L8"PHP" PHP_LANG Nocase Line Comment = // Line Comment Alt = # Block Comment On = /* Block Comment Off = */ Escape Char = \ String Chars = "' File Extensions = PHP PHTML INC PHP3 PHP4

And the HTML code in the file will be formatted as per the section defined as:

Code: Select all
/L3"HTML" Nocase Noquote HTML_LANG Block Comment On = <!-- Block Comment Off = --> Block Comment On Alt = <% Block Comment Off Alt = %> String Chars = "' File Extensions = HTM HTML ASP SHTML HTT HTX JSP

However, my PHP file is lacking any highlighting in the HTML portions of the document. I'm sure that it's probably my misunderstanding of the help files, or my misconfiguration somewhere. But if anyone can get this figured out so I can have two types of highlighting working in my PHP and ASP files I'd appreciate knowing how.

Cheers,

Mike
User avatar
THEMike
Basic User
Basic User
 
Posts: 15
Joined: Mon Nov 01, 2004 12:00 am
Location: UK

Re: Multi-language syntax highlighting for HTML files

Postby THEMike » Tue Feb 08, 2005 6:43 am

I think I have solved this. To syntax highlight double language files:

1) Define HTML to take the file extensions of your PHP/ASP Files:

Code: Select all
/L3"HTML" Noquote HTML_LANG Block Comment On = <!-- Block Comment Off = --> Block Comment On Alt = <% Block Comment Off Alt = %> String Chars = "' File Extensions = HTM HTML SHTML HTT HTX JSP HELP ASP PHP

2) Define VBS/PHP Highlighting to NOT take them:

Code: Select all
/L8"PHP" PHP_LANG Nocase Line Comment = // Line Comment Alt = # Block Comment On = /* Block Comment Off = */ Escape Char = \ String Chars = "' File Extensions = MODULE

Then, ultraedit appears to open your file as L3 (HTML), but see that it is a PHP_LANG file, and thus /also/ apply /L8 (PHP) to the PHP blocks of code.

I don't think I've got it quite right, as my tags <?php and ?> in my /C2:

Code: Select all
/C2"Tags"
<?
<?php
?>

Are not rendered in tag colors, as defined by PHP highlighting.

I've mailed IDM for clarification.
User avatar
THEMike
Basic User
Basic User
 
Posts: 15
Joined: Mon Nov 01, 2004 12:00 am
Location: UK

Re: Multi-language syntax highlighting for HTML files

Postby pietzcker » Tue Feb 08, 2005 9:44 am

I've got the same problem here. I do get PHP highlighting in HTML files if I start the PHP section with <?PHP. I don't get it if I use <?. I don't get HTML highlighting in PHP files, either.

What seems strange to me is that I can't find any indication in the wordfile.txt that shows me how UE determines when "foreign" code sections start. So how does UE "know" that a certain section is in PHP or ASP or whatever? It must be defined someplace, but it doesn't seem to be wordfile.txt...

Confused,
Tim
User avatar
pietzcker
Master
Master
 
Posts: 241
Joined: Sun Aug 22, 2004 11:00 pm

Re: Multi-language syntax highlighting for HTML files

Postby THEMike » Tue Feb 08, 2005 10:07 am

Yes, it seems this only works one way.

Files that are being highlighted as the file that is HTML_LANG can contain blocks of code in the supported [other]_LANG formats. In which case, then the formatter starts formatting via the language defined with [other]_LANG until the end of that block.

Blocks appear to be hard-coded within Ultraedit, so for PHP it's:

Code: Select all
<?php
// Highlighted as PHP
?>

And for ASP it's:
Code: Select all
<%
%>

So, if a file is a .HTML, then:

Code: Select all
THis is highlighted as <b>html</b>.
<?php
echo('this will highlight as PHP');
?>
<?php echo('this will highlight as HTML'); ?>
<%
Response.Write "This will highlight as ASP"
%>
<% Response.Write "This will highlight as HTML" %>

Which makes the highlighting a bit too hit-and-miss when working with the horrible ASP I'm maintaining. Plus, the changes mean I can't go back to my 'old' wordfile with HTML tags defined in the wordfile def of PHP and ASP and HTML and JSP and... because they need the "Old style" HTML_LANG support.

Plus ASP_LANG doesn't appear to have the code-folding definitions in it. Or at least, not the ones VB_LANG has.

Bit of a trade off for me here, I love some of the new features, but I am finding it hard to work with the new syntax highlighting.
User avatar
THEMike
Basic User
Basic User
 
Posts: 15
Joined: Mon Nov 01, 2004 12:00 am
Location: UK

Re: Multi-language syntax highlighting for HTML files

Postby schroep » Wed Feb 09, 2005 1:01 am

Here's what I have found:

In the past I used a combined ASP-HTML-VB wordfile to combine everything I was doing (ASP/HTML web stuff). As this does not seem to work quite right in the new version, I started playing with the new way to do things.

Although ASP_LANG is available to be used, nothing in the default WordFile seems to define it. So, for starters, I imported my ASP-HTML-VB block. View As this type works for syntax highlighting as before, no code folding.

Left the ASP extension solely to the standard HTML definition in the file; ASP code doesn't syntax highlight at all, but HTML code does and Code Folding works in the HTML portions.

Defined my ASP-HTML-VB block as ASP_LANG in the wordfile; now syntax highlighting works in the ASP portion, but no code folding.

Defined some /Open Fold Strings and /Close Fold Strings in my ASP block; now, code folding works (for what I have defined), with a weird caveat; this won't work:

Code: Select all
<%
If True Then
  Response.Write "OK"
Else
  Response.Write "NO"
End If
%>

Oddly, you need something between the <% starting block and the first line for which you want to do code folding (in my case, I defined the IF as a start string), and it can't just be a blank line. A blank line with a space on it, however, works, as would a comment or some line of code with no code fold start strings. Seems to be a bug.

However, my defined INDENT strings don't work in the ASP block; only the HTML indents are working.

So, I'm getting closer. I can get code folding working in both blocks (HTML and ASP), although I have to manually define the ASP portion. Indent strings seem to be being ignored for the ASP portion. I could define them in the HTML block, but then they would overwrite the default indents, which I don't want to lose and have to manually then redefine.

It would really be nice to be able to define INDENT/FOLD/etc. strings that are INCREMENTAL in nature, so that they are added to the defaults, rather than replacing them.

Anyone have more success than this?
User avatar
schroep
Newbie
 
Posts: 2
Joined: Tue Feb 08, 2005 12:00 am

Re: Multi-language syntax highlighting for HTML files

Postby THEMike » Wed Feb 09, 2005 2:40 am

I've been corresponding with support on this highlighting issue, plus some toolbar issues and a crash bug saving new files. They've re-created everything so far, and are fixing the toolbar and crash bug. Not sure where they are at with the syntax highlighting problems:

IDM wrote:> I was under the impression that it could work like the PHP example in
> the wordfile. i.e. the PHP definition contains no HTML markup, but
> contains the PHP_LANG tag, then it picks up HTML highlighting from the
> language definition (which is identified by being the language with
> HTML_LANG defined).

You did everything right. I will look into it. In the meantime it appeared to me that if I View As an HTML file it appeared to be syntax highlighted correctly.

> Attached is a test.asp page which contains two ASP blocks and an HTML
> block, with my wordfile, only the ASP blocks are highlighted. Rogue
> words in the (original) html block were highlighted as they were ASP
> keywords in the text of the html (e.g. <b>Response</b>, the "Response"
> was highlighted as it's an ASP Keyword)

Thanks, I have reproduced this with your information.
User avatar
THEMike
Basic User
Basic User
 
Posts: 15
Joined: Mon Nov 01, 2004 12:00 am
Location: UK

Re: Multi-language syntax highlighting for HTML files

Postby schroep » Thu Feb 17, 2005 11:21 am

I have passed on a bunch of stuff to support, as well, and they have been able to duplicate it (mostly related to syntax highlighting with multiple languages, but a few other issues, such as the function list). This was last week, and they tell me they are working on it. The last email I received (Friday, 2/11) sounded like they were at least a week out on any fixes, though. Hopefully there will be a new hotfix or version upgrade soon.
User avatar
schroep
Newbie
 
Posts: 2
Joined: Tue Feb 08, 2005 12:00 am

Re: Multi-language syntax highlighting for HTML files

Postby Laze » Fri Feb 18, 2005 2:04 pm

None of these php+html hightlighted problems seems to be fixed in the latest version using the patch.

Its strange that if you select hightlight as html - then everything entered after <?php is hightlighted okay - but not with the <?

No matter what i try it doesn't seem to work - although my old wordfile from the 10.20 version seems to be working fine.

Anybody had any luck with fixing this?

Update: I have started using this http://www.ultraedit.com/files/wf/php5.uew instead of the default L8 - it works fine except some folding problems with functions.
User avatar
Laze
Newbie
 
Posts: 1
Joined: Fri Feb 18, 2005 12:00 am

Re: Multi-language syntax highlighting for HTML files

Postby Salinga » Wed Feb 23, 2005 3:14 am

I sent just this email with this suggestion to IDM.



Hi there!

I visited the forum on this issue and I found out that there are some poblems with this issue right now and it seems to be hard coded for PHP.

Is it possible to make it a variable feature by relating hightlight descriptions in the wordfile not only by file extenders but also by area markers?

So like the "File Extensions = js javascript"... you have a

"Area Markers = <script </script>" entry in the wordfile?

For Java-Code in JSP files it would be:

"File Extensions = java"
"Area Markers = <% %>"

So UE doesn't only scan for file extenders but also for this area marker strings to enable a certain syntax highlighting.
User avatar
Salinga
Newbie
 
Posts: 1
Joined: Fri Feb 04, 2005 12:00 am

Re: Multi-language syntax highlighting for HTML files

Postby dave_h » Mon Mar 07, 2005 5:50 pm

The best results have manifested since I removed

Code: Select all
Block Comment On Alt = <% Block Comment Off Alt = %>

from my 11.00 default wordfile's L3 block, the HTML block.

This, in combination with viewing .ASP files as HTML, causes highlighting to behave more like it should with a multi-language file. :|
User avatar
dave_h
Newbie
 
Posts: 2
Joined: Mon Mar 07, 2005 12:00 am

Re: Multi-language syntax highlighting for HTML files

Postby darkdragon-001 » Sun Apr 29, 2012 9:49 am

UltraEdit only highlights strings until the end of the line. When the string continues in another line, this is not correctly recognized.

I'm using UE v15.20. Is this fixed in a newer version or does this problem still exist? What can I do to fix this?
darkdragon-001
Newbie
 
Posts: 7
Joined: Sat Apr 21, 2012 2:45 pm

Re: Multi-language syntax highlighting for HTML files

Postby Mofi » Sun Apr 29, 2012 11:41 am

There is nothing to fix because this is an issue of definition. Since UltraEdit v11.00 multi-line string highlighting is supported. It is by default enabled for all syntax highlighting languages. In first line of a syntax highlighting language definition (= first line of a wordfile nowadays) it is possible to use EnableMLS to explicitly enable, or DisableMLS to disable multi-line string highlighting.

In C/C++ multi-line strings are possible by ending every line of a multi-line string with backslash (the escape character) and therefore EnableMLS can be used. On the other hand most C/C++ programmers never define a string over multiple lines and therefore DisableMLS is often better.

Multi-line strings are very common in HTML files and EnableMLS should be therefore used in html.uew. Standard php.uew contains EnableMLS.

It's a decision of the user. Using Multi-line string highlighting makes syntax highlighting a little bit slower, especially when entering a string and just beginning double or single quote is typed as this results in highlighting everything up to next double or single quote in file as string until the closing double or single quote is typed too.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Multi-language syntax highlighting for HTML files

Postby darkdragon-001 » Sun Apr 29, 2012 12:27 pm

Thanks for your detailed reply :)

This is something else what's missing in the php5.uew file, I attached for the bad function strings: Function strings for PHP files working also with default values.

I attached an edited version for the php5.uew.

BTW: File extension ctp stands for cake template (the php framework I use). If not needed, just remove.

Although I have version 15.20.x, I cannot upgrade (or at least I didn't succeed) UltraEdit to use multiple wordfiles at a time.
Attachments
php5.zip
ZIP file contains edited version of php5.uew file for UE v15.xx
(17.82 KiB) Downloaded 223 times
darkdragon-001
Newbie
 
Posts: 7
Joined: Sat Apr 21, 2012 2:45 pm

Re: Multi-language syntax highlighting for HTML files

Postby Mofi » Mon May 07, 2012 3:06 am

For multi-language syntax highlighting support in UE v15.00 and later, except German special edition UE v15.20.1.1000 SE, you have to

  • specify at Advanced - Configuration - Editor Display - Syntax Highlighting a directory containing the *.uew files each with 1 language. The default path is "%APPDATA%\IDMComp\UltraEdit\wordfiles" with %APPDATA% referencing the value of environment variable APPDATA. The directory displayed must be with real full path to the directory. If you want to use the default wordfiles directory, but currently a single wordfile or a different directory is set, simply delete the entire string and close the configuration dialog with button OK. On next opening the configuration the path is correct set to default wordfiles directory.
  • Next each *.uew file should contain only exactly 1 syntax highlighting definition. Open all the *.uew files in the configured directory with UltraEdit and verify that.
  • Verify that there is only 1 *.uew file which contains language marker HTML_LANG (for HTML)
  • Verify that there is only 1 *.uew file which contains language marker CSS_LANG (for CSS)
  • Verify that there is only 1 *.uew file which contains language marker JSCRIPT_LANG (for Javascript)
  • Verify that there is only 1 *.uew file which contains language marker PHP_LANG.
  • Verify that there is only 1 *.uew file which contains language marker ASP_LANG (for ASP using VBScript).
  • The file extensions of files containing 2 or more of above languages must be all listed on end of first line of the wordfile containing HTML_LANG.
Other wordfiles can share a language marker string like XML_LANG which can be used in several wordfiles.

I don't know what is ECMA_LANG for as I have never seen it in any wordfile. I suppose that UltraEdit interprets this language marker like JSCRIPT_LANG and therefore it should exist also only in 1 wordfile.

Files with a file extension associated directly to a wordfile containing CSS_LANG, JSCRIPT_LANG, PHP_LANG or ASP_LANG should always contain only this language and never any other language embedded as multi-language syntax highlighting is enabled only for files associated with the wordfile containing HTML_LANG. For example if your *.php files contain usually only PHP code and no other language, you have to specify file extension PHP nevertheless in the wordfile containing HTML_LANG if some of your *.php files contain HTML sections. You should specify file extension PHP only in the wordfile containing PHP_LANG if ALL your PHP files contain only PHP code.

PS: Multi-language syntax highlighting works in the same way for UltraEdit prior v15.00 and German UE v15.20.1.1000 SE with the difference that a single wordfile instead of a wordfiles directory must be specified and the single wordfile contains up to 20 syntax highlighting languages, but just 1 language for HTML, 1 for CSS, 1 for Javascript, 1 for PHP and 1 for ASP. A single wordfile is also supported by UE v15.00 and later for downwards compatibility after an upgrade.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Syntax Highlighting