Convert html to rtf and back again

I’m building a very simple web page editor. My intention is to load and save html files, and edit them in a styled text area in my editor app. To handle the loading and saving, I need to convert between html and rtf. I found a couple of previous discussions on the forum for doing this.

The first, for converting from rtf to html is here:
https://forum.xojo.com/search?q=rtf%20to%20html
The solution given in this discussion is fine for my purposes.

The second, for converting from html to rtf is here:

Unfortunately, there is no code posted in this second discussion, just external links which are now dead. @Tim_Parnell posted a link to a project that would likely suit my needs. Tim, if you see this, is the code still available, and if so, can you post a link? Otherwise, I’m open to any other solutions.

I’m working on a Mac, and would be okay with Mac only solutions.

Pandoc maybe useful for you

https://pandoc.org/index.html

You may better just do the editing in a htmlviewer.

We got things like Editable property in WebViewMBS, IEEditableMBS in HTMLViewer and in general you may just switch it with JavaScript: document.body.contentEditable = true;

Then people can type in the HTMLViewer and you don’t need to convert.

I believe you may be talking about Tim Parnell’s HTMLEdit component, which I purchased years ago and included in GraffitiSuite. Since then it’s been replaced by GraffitiEditor. GraffitiEditor allows your users to edit HTML in a WYSIWYG manner, and has tons of features and customization options. There are both Web and Desktop versions.

You can download the GraffitiSuite Demo to check it out.

2 Likes

I am converting between rtf (Desktop/Styled Text Area) and HTML for web in a couple of apps.
For desktop I iterate the style runs and save the output as needed.
For web I iterate the string looking for tags and then generate ‘style runs’.
I save the output for both in JSON so I can load both back as needed, but you could just parse the HTML as needed on desktop, and then save the RTF back as HTML, generating the HTML from style runs.

2 Likes

Thanks for the replies. I’ll check out the suggested resources.

In my first post, I should have provided more information about what I was trying to accomplish.

I have a website that was created with iWeb several years ago. iWeb won’t run on anything newer than MacOS Sierra. I can still boot Sierra on one of my computers and run iWeb. However, the site file has become corrupted over the years. When I try to edit one of the existing pages, random formatting changes happen, resulting in an ugly mess. Fortunately, the web pages are very simple technical articles with minimally formatted text with some images inserted.

After reading the replies above, and doing a lot of thinking, I’ve decided to build a basic app that uses Markdown as the main facility for entering text and image links, with a Markdown to html converter to generate the web pages, and an html viewer to view the rendered pages. I think this will be the best way to manage the web pages going forward.