FXMisc / RichTextFX

Rich-text area for JavaFX
BSD 2-Clause "Simplified" License
1.21k stars 236 forks source link

RichTextFX highlight two languages in one CodeArea? #136

Closed mathiasene closed 9 years ago

mathiasene commented 9 years ago

Hello everyone, I'd like to know how to highlight PHP and HTML in the same CodeArea. I've tried a lot with if (newValue.startsWith("<?php")) { //I Use } and newValue.startsWith("?>") and so on. How can I do that? I've tried a lot...

TomasMikula commented 9 years ago

This is something related to how you parse the source code. RichTextFX does not tell you how to parse your source code. The flip side is that it does not provide you with any support for parsing. All it cares about are the style ranges computed from the result of your parser. The demos provided with RichTextFX use regular expressions to parse Java tokens. For more sophisticated parsing, you might want to use something else, like ANTLR or Parboiled, just to name a couple. Or you can keep hacking with regular expressions, but their power is limited.

So I suggest:

  1. Choose your parsing method.
  2. Find out how to parse HTML + PHP using that method. (RichTextFX might not be the best place to get help on that.)
  3. We can then help you with how to use the parse result to highlight text in RichTextFX.