HTML to attributed string or similar

I dont’ suppose there’s an off-the-shelf solution for going from basic HTML (bold, LI, OL tags) to a nice rendering in JUCE without actually usingthe web browser component?

I’ve got a lot of text in a database I’d like to display nicely for the user.

Hi @jimc,

I also needed this for a project at ROLI, so a while back, I hacked together a quick and dirty tool which can convert .rtf files to an AttributedString.

The .rtf file converter only runs on macOS, so I created an intermediate xml format for JUCE’s AttributedString.

So basically, you use a mac and the tool that I wrote, to convert an .rtf to this xml format. You can then use this xml file to create an AttributedString on any other platform.

I’ve pushed the code of this tool to my private github repo. It basically provides the following API:

struct AttributedStringSerializer
{
    static AttributedString* createAttributedStringFromInputStream (InputStream& stream);
    static void writeAttributedStringToOutputStream (const AttributedString& str, OutputStream& stream);

    static AttributedString* createAttributedStringFromFile (const File& inputFile);
    static void writeAttributedStringToFile (const AttributedString& str, const File& outFile);

   #if (JUCE_MAC || JUCE_IOS)
    static AttributedString* createAttributedStringFromRTFData (InputStream& stream);
    static AttributedString* createAttributedStringFromRTFFile (const File& rtfFile);
   #endif
};

The code is not part of JUCE and not very well tested, hence I cannot guarantee that it will work or provide any support for it.

3 Likes