A robust JavaScript library to convert RTF (Rich Text Format) strings to clean, readable HTML.
npm install rtf-to-html-converterconst { convertRtfToHtml } = require('rtf-to-html-converter');
const rtf = String.raw`{\rtf1\ansi\ansicpg1252\deff0\nouicompat{\fonttbl{\f0\fnil\fcharset0 Arial;}{\f1\fnil\fcharset0 Arial Black;}}{\colortbl ;\red64\green64\blue64;\red255\green0\blue0;}{\pard\fs30{\b\cf1 Main symptoms:}\sb70\par}{\pard{\b\cf2 Warning in red}\sb70\par}}`;
const html = convertRtfToHtml(rtf);
console.log(html);- Converts RTF to HTML with support for:
- Bold, italic, and underline text
- Text color (RTF color table and
\cfNcodes) - Unicode characters (e.g.
\u237?) - Bulleted and numbered lists
- Paragraph and line break handling
- Non-breaking spaces
- Cleans up empty paragraphs and extra whitespace
- Compatible with both JavaScript and TypeScript projects (includes type definitions)
- Outputs HTML using
<div>,<strong>,<em>,<u>,<span style="color:...">,<ul>,<li>, etc.
- Does not support RTF tables, images, or embedded objects.
- Only basic text formatting is supported (bold, italic, underline, color, lists, paragraphs).
- Font face and font size are ignored.
- Complex nested RTF structures may not be fully converted.
- Only the color table defined in the RTF is used for color conversion.
- Output is intended for display, not for round-trip editing back to RTF.
Converts an RTF string to HTML.
rtf(string): The RTF string to convert.
string: The resulting HTML string.
<div><strong style="color: rgb(64,64,64);">Main symptoms:</strong></div>
<div> </div>
<div><strong style="color: rgb(255,0,0);">Warning in red</strong></div>In your VS Code terminal, run:
node testISC
This repository is open source and free to use under the ISC license.
Only the original author can modify or publish new versions to this repository and npm.
If you wish to suggest improvements, please open an issue or a pull request—changes will only be merged at the author's discretion.
Marcelo Saravia
- Email: molinos456@hotmail.com, molinito48@gmail.com
- LinkedIn: linkedin.com/in/marcelo-saravia-27128092
- GitHub: github.com/molinito
If you find this library useful, you can support its development by buying me a coffee:
Paypal: paypal.me/molinito12