HTML Syntax Highlighter

Questions on using RSyntaxTextArea should go here.

Moderator: robert

HTML Syntax Highlighter

Postby _ » Sun Jan 22, 2012 6:00 pm

Hello.

The following HTML isn't highlighted correctly, validated with http://validator.w3.org/.

Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   <title>Some Title</title>
   <script language="JavaScript" type="text/javascript">// <![CDATA[
      var x = "";
   // ]]></script>

</head>
<body>
   <div id="a">
      <div id="b">
         Some content.
      </div>
   </div>
</body>
</html>


The closing tag "</script>" shouldn't be highlighted as comment but as the end of the script.
As it is highlighted as comment the rest of the document is highlighted as JavaScript.

Best regards.
_
 

Re: HTML Syntax Highlighter

Postby robert » Sun Jan 22, 2012 6:29 pm

Thanks for finding this, I'll look into it. Should also affect PHP and JSP as well.
User avatar
robert
 
Posts: 797
Joined: Sat May 10, 2008 5:16 pm

Re: HTML Syntax Highlighter

Postby robert » Sun Jan 22, 2012 11:44 pm

Just fixed this in SVN. Check it out and let me know if you find any other problems!
User avatar
robert
 
Posts: 797
Joined: Sat May 10, 2008 5:16 pm

Re: HTML Syntax Highlighter

Postby _ » Mon Jan 30, 2012 2:22 pm

Hello.

Thank you for your prompt fix and reply.

Tested with the latest trunk revision (391).
The strings assigned to the variables x, y and z are incorrectly highlighted as errors.

Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <title>Some Title</title>
  <script language="JavaScript" type="text/javascript">// <![CDATA[
    var x = "\\";
    var y = "\x01";
    var z = "\a \/";
  // ]]></script>
</head>
<body>
  <div id="a">
    <div id="b">
      Some content.
    </div>
  </div>
</body>
</html>


Best regards.
_
 

Re: HTML Syntax Highlighter

Postby robert » Tue Jan 31, 2012 1:59 pm

Thanks, will fix this ASAP. Was ready to upload a "fix" that no longer differentiated between valid and invalid string literals, but then decided to not take the easy way out. :D
User avatar
robert
 
Posts: 797
Joined: Sat May 10, 2008 5:16 pm

Re: HTML Syntax Highlighter

Postby robert » Thu Feb 02, 2012 3:46 am

Fixed in SVN commit 392. Should now properly colorize multi-line strings (ending with '\'), and detect errors when there are invalid unicode or \xNN escapes.

Let me know if you find any more problems!
User avatar
robert
 
Posts: 797
Joined: Sat May 10, 2008 5:16 pm

Re: HTML Syntax Highlighter

Postby _ » Sun Feb 05, 2012 12:41 am

Hi.

Thanks again for your prompt fix and reply.
Glad you didn't take the easy way.

Tested with the latest trunk revision (394).
The following HTML isn't highlighted correctly, validated with http://validator.w3.org/.
The closing tag "</script>" shouldn't be highlighted as comment but as the end of the script.

Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Some Title</title>
        <script language="JavaScript" type="text/javascript">// <![CDATA[
            /*
        // ]]></script>
    </head>
    <body>
        <div id="a">
            <div id="b">
                Some content.
            </div>
        </div>
    </body>
</html>

Some enhancement requests:
- Could you add CSS syntax highlighting to the HTML syntax highlighter?
- Could you change the JavaScript syntax highlighter to be equal to the JavaScript of the HTML syntax highlighter?, as the JavaScript of the HTML syntax highlighter has more "highlighting".

Best regards.
_
 

Re: HTML Syntax Highlighter

Postby robert » Sun Feb 05, 2012 5:53 am

I've fixed the JS issue, and updated the plain JavaScript TokenMaker to behave like that used when highlighting HTML. The only thing left you asked for is CSS highlighting in HTML. Can you please try out the current CSS syntax style and let me know if it meets your needs? You've provided some great feedback for other languages so far, and if there are any tweaks you're going to want for CSS, it'd be better to know them now than to wait until it's been added into HTML, JSP, and PHP (unfortunately it's not really possible to share syntax highlighting code amongst different syntax styles, so it must be copy-and-pasted, so I'd like to make sure the current CSS support is sufficient before proceeding).
User avatar
robert
 
Posts: 797
Joined: Sat May 10, 2008 5:16 pm

Re: HTML Syntax Highlighter

Postby _ » Sun Feb 05, 2012 9:53 pm

Hi.

Once again thanks for your prompt reply and fix.

One enhancement request to the JavaScript syntax highlighting:
- Add syntax highlight/awareness of regular expression literals (i.e. /^a$/i), as sometimes it breaks the syntax highlighting of the code following the regular expression literals (e.g. mostly when it has double quote or single quote characters).


Regarding the CSS syntax highlighting it would be great to have more highlighting in the properties and values.

Some issues of the current CSS highlighting:
- The syntax colour of the "someid" id selector is the same as the value of the property "color";
- The value of the property "color" of the "someclass" class selector is not highlighted correctly (i.e. "(").
Code: Select all
#someid {
    color: #3f3f3f;
}
.someclass {
    color: rgb(0,255,0);
}


Best regards.
_
 

Re: HTML Syntax Highlighter

Postby robert » Mon Feb 06, 2012 5:46 pm

Regex highlighting for JavaScript has been added (more important since it breaks highlighting). I don't know if it's 100% accurate, but I believe it matches the behavior in Eclipse's JS editor and should be sufficient 99% of the time. CSS-in-HTML is still not there yet.
User avatar
robert
 
Posts: 797
Joined: Sat May 10, 2008 5:16 pm

Next

Return to Help

Who is online

Users browsing this forum: No registered users and 1 guest

cron