Question:
How do I convert an RTF string to a Markdown string (and back) either in C# or JS, ideally without wrapping an exe?
I have a legacy product that uses .NET's RichTextBox
control. Forms that use it save their output in Microsoft's proprietary RTF format. Here is a small example of the output it can generate:
{\\rtf1\\ansi\\ansicpg1252\\uc1\\htmautsp\\deff2{\\fonttbl{\\f0\\fcharset0 Times New Roman;}{\\f2\\fcharset0 GenericSansSerif;}}{\\colortbl\\red0\\green0\\blue0;\\red255\\green255\\blue255;}\\loch\\hich\\dbch\\pard\\plain\\ltrpar\\itap0{\\lang1033\\fs18\\f2\\cf0 \\cf0\\ql{\\f2 {\\ltrch Some content here }\\li0\\ri0\\sa0\\sb0\\fi0\\ql\\par}\r\n}\r\n}
My C# .NET Core Web App needs to be able to use this stored RTF to display a "Rich Text Editor" on a web page, have the ability to update the value, and save in a format that can still be used by the legacy product.
Unfortunately, I am having trouble finding existing/modern web components that can use RTF as input. Most appear to use markdown or a custom JSON format.
Ideally, I would like to:
- Convert the existing RTF to Markdown using either:
- Server side, using C#
- Client side, using JS
- Use the markdown with one of the existing Rich Text Editing web components I've found.
- On save, convert the web component's markdown to RTF before persisting
So far, I have tried:
- Following this CodeProject write-up for creating a custom RTF -> HTML converter: Writing Your Own RTF Converter
- I can get it to work in a .NET Framework project, but not .NET Core
- Using this NuGet Package: RtfPipe
- Throws null reference errors in .NET Core projects
- Using this Node Module: rtf-to-html
- Only support a small subset of RTF, creates an entire HTML document instead of a string/subset, breaks on my specific example
Note: The things I've tried are from RTF -> Html because I couldn't find anything for RTF -> Markdown specifically. My hope was that I could, if I had to, do: RTF -> HTML -> Markdown (and in reverse) as a last resort.