Syntax highlighting in files that contain HTML, Javascript and PHP

169 views
Skip to first unread message

Alan Storm

unread,
Jan 22, 2010, 1:22:27 PM1/22/10
to BBEdit Talk
The follow screenshot is a simplified version of a PHP view file I was
recently working on with "HTML" selected as the language (actual text
included at the end of this email)

http://alanstorm.com/testbed/as_html.png

On line 17 the syntax highlighting goes pear shaped. (note the
different color <p> tags)

If I switch the language to Javascript, the code in the script block
looks right, but the HTML and PHP lose their syntax highlighting. If
I switch the language to PHP a similar problem occurs.

Is there a way to use BBEdit to ensure that files which contain PHP,
HTML and Javascript (common in PHP MVC view files as well as legacy
PHP applications) syntax highlight correctly without toggling back and
forth between HTML and Javascript?

Thanks for any help, or even a definitive "Nope, that can't be done"!

--
Alan Storm
http://alanstorm.com

Actual Text from Screenshot
--------------------------------------------------
<?php
echo "This is a test";
?>
<!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>
<title>Untitled</title>
<meta name="generator" content="BBEdit 9.2" />
</head>
<body>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#order_summary tr').click(function(e){
if(jQuery(this).is('tr.info'))
{
jQuery('#row_detail_'+numeric_id+' td').html('<p>Loading</p>');
}
});
});

var foo = "No Color";

</script>
</body>
</html>

Jim Correia

unread,
Jan 22, 2010, 1:51:44 PM1/22/10
to bbe...@googlegroups.com
On Jan 22, 2010, at 1:22 PM, Alan Storm wrote:

> The follow screenshot is a simplified version of a PHP view file I was
> recently working on with "HTML" selected as the language (actual text
> included at the end of this email)
>
> http://alanstorm.com/testbed/as_html.png
>
> On line 17 the syntax highlighting goes pear shaped. (note the
> different color <p> tags)

BBEdit’s syntax coloring engine always use the HTML rule for ending non-HTML data sections.

See <http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.3.2> for details.

Instead, write the line as:

jQuery('#row_detail_'+numeric_id+' td').html('<p>Loading<\/p>’);

- Jim

Alan Storm

unread,
Jan 22, 2010, 4:13:34 PM1/22/10
to BBEdit Talk
Thanks for the clarification Jim. It's good to know that BBEdit
sticks to the standard on this kind of thing and encourages good
practices.

I use BBEdit to deal with other people's code on a regular basis, and
there's a significant number of real world script blocks that don't
conform to the HTML 4.01 Specification. I would find it useful if
there was a feature in BBEdit that was able to display the syntax
highlighting of these incorrectly coded pages as the uneducated and/or
rushed authors intended (pages that still work, and might even be
valid HTML 5) ). I believe that other people would find this useful
as well. Please consider this message a feature request to that
effect.

In case it's not obvious, this is a request and not a demand.

Thanks again.

Peter Weil

unread,
Jan 26, 2010, 1:25:58 PM1/26/10
to bbe...@googlegroups.com
Along similar, but slightly different lines, is there a way to get BBEdit's syntax coloring engine to work in a situation such as the following example, where I'm testing to see whether or not to add an id attribute to an <li> tag?

<ul id="nav_alpha">

<?php

$letters = range('a', 'z');

foreach ($letters as $first_letter) : ?>

<li<?php

if([condition1])
{
echo '';
}
elseif ([condition2])
{
echo ' id="my_id"';
}
?>
></li>

<?php endforeach; ?>

</ul>

> --
> You received this message because you are subscribed to the
> "BBEdit Talk" discussion group on Google Groups.
> To post to this group, send email to bbe...@googlegroups.com
> To unsubscribe from this group, send email to
> bbedit+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/bbedit?hl=en
> If you have a feature request or would like to report a problem,
> please email "sup...@barebones.com" rather than posting to the group.

Reply all
Reply to author
Forward
0 new messages