Android Tutorial [B4X] [B4XPages] BCTextEngine parser: B4X Code Highlighter

java_QIDqgmNTqq.png


firefox_5AjleJ4uQg.png


This is an example of creating a custom parser for BBCodeView. It depends on BCTextEngine v1.61+ which allows setting the text runs directly instead of parsing the BBCode.

The parser is compatible with B4A, B4J and B4i. Note that in B4J the text looks less clear with the dark theme due to the antialiasing method used and the small text. It does look good with the dark theme in B4A and B4i.

The class is included in the B4A example.

It is an example. It doesn't support all of B4X programming language features.
 

Attachments

  • CodeHighlighter.zip
    14.4 KB · Views: 733
Last edited:

LucaMs

Expert
Licensed User
Longtime User
There is a bug; parsing this line:
B4X:
           Page1.Title = $"$1.2{fraction * 100}%-${url}"$
 

LucaMs

Expert
Licensed User
Longtime User
Parsing smart strings, and especially multiline smart strings, is quite complex. As written in the first post this parser was written as an example and it doesn't support all of B4X features.
Which means: fix it yourself 😄

Too bad, my laziness hoped the author would do it 🤣
 

LucaMs

Expert
Licensed User
Longtime User
I know; that problem, anyway, is that it crashes. If it doesn't recognize some element, keeping its default color but without crashing ...!
 
Top