HTML tags in PHP code

SyntaxEditor for Windows Forms Forum

Posted 13 years ago by Kasper
Version: 4.0.0237
Avatar
Hi,

In my application, I often need to obtain the current HTML tag, that is, the tag the cursor is currently within. I'm doing this the "SyntaxEditor way", by obtaining a TokenStream and looping through it to find the beging and the end of the tag. This works fine, as long as it's actually HTML. However, I will need to do this with HTML tags within PHP code as well, like this:

<?
echo "<a href=\"http://www.actiprosoftware.com\">Test</a>";
?>
I could of course do some regular parsing, but I thought it would be easier to add some states and stuff to the PHP.xml file. I have added the StartTagState and EndTagState from HTML.xml to the file, and configured both DoubleQuoteStringState and SingleQuoteStringState to allow these as childstates. This works surprisingly well, except for one thing: The editor no longer recognizes escaping within the string if it's inside an HTML tag. In the example above, the > of the <a> tag will not be highlighted as a part of the tag. If I remove the two \ characters, it works fine, but of course the PHP code won't work, since the " characters needs to be escaped :). I might be missing something obvious here, but I'm hoping that you can help me make this work.

Comments (6)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Well in this case you'd probably just have to modify the HTML language code (that can be embedded in your PHP) to use \" as an attribute delimiter instead of only the " character.


Actipro Software Support

Posted 13 years ago by Kasper
Avatar
Hi,

I'm not sure that would work, since both ' and " can be used in PHP? Something like echo 'test"ing'; would be valid.
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
You can add ' as its own scope pattern set as well. You'd have to code the '' as an escape sequence or perhaps instead, for the end scope, put a lookahead on it that says the next character cannot be a ' character.


Actipro Software Support

Posted 13 years ago by Kasper
Avatar
Sorry, but I'm not quite sure how that should be done - could you possibly post some example code? That would be really great :)
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Just in anyone is reading this, we helped Kasper over email.


Actipro Software Support

Posted 13 years ago by Kasper
Avatar
Yes, it works perfect now, thanks to the always competent support from Actipro Software. I really do feel better about choosing SyntaxEditor and the rest of the controls everytime I talk to these people :)
The latest build of this product (v2018.1 build 0341) was released 7 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.