Converting TextArea styled text (RTF) to Markdown?

I’m interested in converting the styled text contents of a TextArea as Markdown. Before attempting to write my own RTF → Markdown converter, I wonder if someone has written a Xojo (or MBS) solution for this already. It doesn’t need to deal the full range of RTF, just the relatively small subset supported by TextAreas.

1 Like

Yes, Garry has one that parses Markdown lightning fast, but you’ll need to write the RTF renderer. Garry’s design is extremely flexible and this should be possible, it’s just work no-one has done for free yet.

1 Like

I’m not aware of TextArea → Markdown converter, but it shouldn’t be hard. There isn’t much overlap in styles supported by TextArea and Markdown (just bold, italic, and underline, I think). You can get these just by reading through the StyleRuns in the StyledText property and write the equivalent Markdown.

If you have a defined style for something like a Markdown heading or preformatted code block, you could similarly detect that style and then write the equivalent markdown out. You might consider making these definable because the actual StyledText rendering could vary in terms of font, fontsize, etc.

this is a rtftohtml method. found on this forum.
the rtf comes from easily from a textarea.
it shouldn’t be difficult to translate it to markdown instead of html.

Thanks to everyone who offered suggestions. It is rather straightforward to convert styles from styled text to markdown, but there are a few additional details to take care of, like escaping reserved characters, modifying URLs, and in my case handling font name, size, and color. But it’s not a lot of work.

Oops I misunderstood you and got it backwards sorry :grimacing: