Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse - how to extend HTML editor to add custom tags?

Tags:

html

eclipse

tags

I write an application and inside of HTML code I have custom tags (of course these tags are parsed on server side and end user gets them as valid HTML code). Example of custom tag usage:

<html>
<body>
...
    <Gallery type="grid" title="My Gallery" />
...
</body>
</html>

1.) How can I have eclipse recognize my custom tags inside of HTML code and add syntax highlighting to them?
2.) How can I add auto-suggestions to my custom tags? For example if I type "<Gallery " press "Ctrl+Space" - in the list of available attributes it shows me "type" and "title" and if I type "<Gallery type=" press "Ctrl+Space" I would see list of available values only for tag "Gallery" and its attribute "type".

Thanks in advance!

like image 270
dmitry7 Avatar asked May 14 '11 08:05

dmitry7


2 Answers

Not really what you want, but maybe it helps you:

  1. You can try the Aptana Plug-in for Eclipse. It allows to write your own regular expression for HTML validation, so a custom tag would be ignored by the validator. E.g.:

    .gallery.

  2. Eclipse allows you to add simple auto-suggestions via Templates. On Eclipse 3.7.1 (Indigo) + PHP Dev Tools (PDT) 3.0.0: Window > Preferences > Web > HTML Files > Editor > Templates

like image 57
malisokan Avatar answered Sep 22 '22 03:09

malisokan


Sadly, there is no easy way: you have to roll your own parser for this, and then add both your extra elements and the base grammar (HTML) to it.

If you have your parser, you could use it to do syntax highlighting (strictly speaking, for that simple lexing is enough); and a good parser can support content assist (auto-suggestions in your terminology).

Caveats:

  • Creating a parser for HTML is not an easy task. Maybe by aiming at a more often used subset is feasible.
  • If a parser exists, the editor parts are still hard to get well.

Some help on the other hand: you could use some text editor generators to ease your work:

  • Eclipse IMP http://www.eclipse.org/imp/ can in theory handle any type of parser, but currently it is most optimized for LPG. The documentation is scarce, but the developers are helpful in the forums.
  • Xtext http://www.eclipse.org/Xtext/ got quite a hype for creating text editors for DSLs. The generated editors are quite nice out of the box, but is not the best solution for large files. Has a really helpful developer community.
  • EMFText http://www.emftext.org/index.php/EMFText is a lesser known entity - I don't know it in details, but I guess, it is similar to Xtext.
like image 29
Zoltán Ujhelyi Avatar answered Sep 22 '22 03:09

Zoltán Ujhelyi