title: How do I convert an RTF string to a Markdown string (and back) (C# .NET Core, or JS)
body: <h1>Question:</h1>
  
  <p>How do I convert an RTF string to a Markdown string (and back) either in C# or JS, ideally without wrapping an exe?</p>
  
  <hr>
  
  <p>I have a legacy product that uses .NET's <code>RichTextBox</code> control. Forms that use it save their output in Microsoft's proprietary <a href="https://en.wikipedia.org/wiki/Rich_Text_Format" rel="nofollow noreferrer">RTF format</a>. Here is a small <strong>example</strong> of the <strong>output</strong> it can generate:</p>
  
  <pre><code>{\\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}
  </code></pre>
  
  <p>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.</p>
  
  <p>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. </p>
  
  <h2>Ideally, I would like to:</h2>
  
  <ol>
  <li>Convert the existing RTF to Markdown using either:
  
  <ul>
  <li>Server side, using C#</li>
  <li>Client side, using JS</li>
  </ul></li>
  <li>Use the markdown with one of the existing Rich Text Editing web components I've found.</li>
  <li>On save, convert the web component's markdown to RTF before persisting</li>
  </ol>
  
  <h2>So far, I have tried:</h2>
  
  <ul>
  <li>Following this CodeProject write-up for creating a custom RTF -> HTML converter: <a href="https://www.codeproject.com/Articles/27431/Writing-Your-Own-RTF-Converter" rel="nofollow noreferrer">Writing Your Own RTF Converter</a>
  
  <ul>
  <li>I can get it to work in a .NET Framework project, but not .NET Core</li>
  </ul></li>
  <li>Using this NuGet Package: <a href="https://github.com/erdomke/RtfPipe" rel="nofollow noreferrer">RtfPipe</a>
  
  <ul>
  <li>Throws null reference errors in .NET Core projects </li>
  </ul></li>
  <li>Using this Node Module: <a href="https://github.com/iarna/rtf-to-html" rel="nofollow noreferrer">rtf-to-html</a>
  
  <ul>
  <li>Only support a small subset of RTF, creates an entire HTML document instead of a string/subset, breaks on my specific example </li>
  </ul></li>
  </ul>
  
  <p><strong>Note:</strong> 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.</p>