Simple HTML parser using TextEditor

I thought it was useful to have a component that can parse some simple HTML and format it like a common browser does, and most importantly mixing hyperlinks with normal text. So I made this class that attempts to make some basic parsing without using Regular Expressions, just parses the HTML byte by byte in a single step, adds the resulting setFont(), setColour() and insertTextAtCaret() to the TextEditor, and stores all links into an Array.

File attached. Suggestions for new optimizations are very welcome.

HtmlTextEdit.h (11.1 KB)

EDIT: find improved versions below…

EDIT 2: Full project on GitHub:

2 Likes

Awesome!!

I’m attaching an optimized version that adds some more useful methods, and also allows setting the font-face and appending more HTML blocks and resetting everything.

GSiHtmlTextEdit.h (13.5 KB)

This is an even better version that does less calls to insertTextAtCaret() thus drastically reducing the processing time for bigger HTML texts. I’ve also added support for some more tags, and the ability to call a lambda function when clicking on placemark links like <a ref="#something">.

Hope someone finds it useful. I’m using it for an in-line version of the user’s manual, plus as a replacement for some Labels where I want to mix normal text with hyperlinks.

GSiHtmlTextEdit.h (17.2 KB)