php syntax coloring inside of html tag

156 views
Skip to first unread message

ryentzer

unread,
Jun 18, 2011, 11:17:22 PM6/18/11
to BBEdit Talk
At times when I have php inside of an html element the coloring of the
php does not always show correctly.

In this instance:
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
the <?php post_class() ?> is the same color as the html element, and
the id="post- is the foreground color, not the html element color.

Here is a link to a screenshot.

http://forbenmedia.com/online/syntaxColoring.png

I have the page set as HTML.

I tried to search on this issue but could not find a resolution.

Thanks, Rick

ryentzer

unread,
Jun 19, 2011, 10:39:29 PM6/19/11
to BBEdit Talk
I also just noticed in the above example that the code folding for
this is also broken.

newto...@gmail.com

unread,
Jun 20, 2011, 12:01:22 AM6/20/11
to BBEdit Talk
This whole issue with php and html has been a long-standing problem
for me. In my workflow where I have lots of mixed php and html, I
often have to create a temp html file to make sure all my div's close
and copy it back and forth - - a real pain that is enough for me to re-
think BBEdit. I have written to about this both here and to the
company but no real response. So - plus one for any improvement in
this area.

S

ryentzer

unread,
Jun 20, 2011, 12:17:29 PM6/20/11
to BBEdit Talk
This has certainly caused me some grief. I was having an error with my
php and I ended up opening the page in another editor so I could
figure out where I made the error. That is certainly something I don't
want to have to do. I've used BBedit for years and prefer to stick
with one editor. Hopefully this issue will be addressed.

While I'm at it I would love to see a more robust syntax coloring/
recognition possibly similar to what aptana/netbeans offers.

On Jun 20, 12:01 am, "newtonp...@gmail.com" <newtonp...@gmail.com>
wrote:

Steve Piercy

unread,
Jun 20, 2011, 4:27:15 PM6/20/11
to BBEdit Talk
On Jun 18, 8:17 pm, ryentzer <r...@forbenmedia.com> wrote:
> At times when I have php inside of an html element the coloring of the
> php does not always show correctly.
>
> In this instance:
> <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
> the <?php post_class() ?> is the same color as the html element, and
> the id="post- is the foreground color, not the html element color.
>
> Here is a link to a screenshot.
>
> http://forbenmedia.com/online/syntaxColoring.png
>
> I have the page set as HTML.

I wrote a Codeless Language Module for Lasso a while back, and
included some scripts in the .zip file that allow you to use a
keyboard shortcut to switch between Language Modes. Skip all the stuff
about how I made the CLM and read the "Installation Instructions".
http://www.stevepiercy.com/lasso_stuff/bbedit_ldml_syntax.lasso

Substitute "PHP" for "Lasso". Same concept. All you need to do is
modify keyboard shortcuts and the AppleScripts to taste.

--steve

ryentzer

unread,
Jun 21, 2011, 12:01:38 PM6/21/11
to BBEdit Talk
Hey Steve thanks for the scripts. However whether I set the language
to PHP or HTML, the problem still exists. The syntax coloring and
folding is wrong. Thanks.

On Jun 20, 4:27 pm, Steve Piercy <steve.piercy....@gmail.com> wrote:
> On Jun 18, 8:17 pm, ryentzer <r...@forbenmedia.com> wrote:
>
> > At times when I have php inside of an html element the coloring of the
> > php does not always show correctly.
>
> > In this instance:
> > <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
> > the <?php post_class() ?> is the same color as the html element, and
> > the id="post- is the foreground color, not the html element color.
>
> > Here is a link to a screenshot.
>
> >http://forbenmedia.com/online/syntaxColoring.png
>
> > I have the page set as HTML.
>
> I wrote a Codeless Language Module for Lasso a while back, and
> included some scripts in the .zip file that allow you to use a
> keyboard shortcut to switch between Language Modes. Skip all the stuff
> about how I made the CLM and read the "Installation Instructions".http://www.stevepiercy.com/lasso_stuff/bbedit_ldml_syntax.lasso

Steve Piercy

unread,
Jun 21, 2011, 4:22:32 PM6/21/11
to BBEdit Talk
On Jun 21, 9:01 am, ryentzer <r...@forbenmedia.com> wrote:
> Hey Steve thanks for the scripts. However whether I set the language
> to PHP or HTML, the problem still exists. The syntax coloring and
> folding is wrong. Thanks.

Sounds like your idea of "right" is different from mine. It works for
me.

What exactly is "wrong" and what would make it "right"?

--steve

ryentzer

unread,
Jun 22, 2011, 8:56:45 AM6/22/11
to bbe...@googlegroups.com
My apologies Steve, it does indeed work correctly. My syntax coloring was throwing me off a bit.
As an aside, I tried this same situation in several other editors and many of them incorrectly colored the code as well. Only two of the ones I tried got it correct. But BBEdit gets so many other things right.

Thanks, Rick

Steve Piercy

unread,
Jun 22, 2011, 12:20:40 PM6/22/11
to BBEdit Talk
On Jun 22, 5:56 am, ryentzer <r...@forbenmedia.com> wrote:
> My apologies Steve, it does indeed work correctly. My syntax coloring was
> throwing me off a bit.

Glad to hear it!

I use this to switch syntax coloring between my programming language,
HTML and javascript, all with a keyboard shortcut in BBEdit to fire
off the AppleScript.

--steve

Lorin Rivers

unread,
Jun 22, 2011, 3:22:59 PM6/22/11
to bbe...@googlegroups.com
Rick, actually, I think BBEdit is doing it right in this case, it looks like your syntax is in error.

Try this:
<div class="<?php post_class(); ?>" id="post-<?php the_ID(); ?>">

Pastebin also has trouble with the syntax as presented: <http://pastebin.com/t7V37aQJ>

Cheers!

Also, Steve, thanks for AppleScripts.

> --
> 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.
> Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

--
Lorin Rivers
Mosasaur: Killer Technical Marketing <http://www.mosasaur.com>
<mailto:lri...@mosasaur.com>
512/203.3198 (m)


Sebastian Becker

unread,
Aug 24, 2011, 1:05:47 PM8/24/11
to bbe...@googlegroups.com
Hi, is there any good solution for this?

I think it's not so rare that php/html - code is mixed up in one document. I just switched from Coda because BBEdit does many things better than Coda - but i didn't even think about that highlighting issue.

There is a document type / syntax mode for "Ruby in HTML" but what I really would appreciate is "PHP in HTML" or even better "Wordpress in HTML" : )

best regards


Watts Martin

unread,
Aug 24, 2011, 2:43:58 PM8/24/11
to bbe...@googlegroups.com
Sebastian Becker wrote:

> I think it's not so rare that php/html - code is mixed up in one
> document. I just switched from Coda because BBEdit does many things
> better than Coda - but i didn't even think about that highlighting issue.

> There is a document type / syntax mode for "Ruby in HTML" but what I
> really would appreciate is "PHP in HTML" or even better "Wordpress in
> HTML" : )

If you set the document type to HTML, then you get PHP (and CSS and
Javascript) syntax highlighting along for the ride automatically, and
the "clipping set" will also automatically change based on language as
you move through the document.

The case that BBEdit can't highlight correctly that Coda can in this
regard is in tag attributes:

<p><a href="<?php echo $url ?>">Click Here!</a></p>

Coda would correctly switch to the PHP scope in the HREF, while BBEdit
remains in HTML scope.

(Then again, with BBEdit I can use the "Close Tag" command to close the
</a> and </p> in that scenario, whereas Coda will be confused by the ?>
at that point, so everything's a bit of a tradeoff.)

--
Watts Martin <lay...@gmail.com>

Reply all
Reply to author
Forward
0 new messages