Convert text RTF to HTML
npm install rtf-to-html-convertersh
npm install rtf-to-html-converter
`
Usage
`js
const { 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);
`
Features
- Converts RTF to HTML with support for:
- Bold, italic, and underline text
- Text color (RTF color table and \cfN codes)
- 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 , , , , , , , etc.
Limitations / Known Issues
- 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.
API
$3
Converts an RTF string to HTML.
#### Parameters
- rtf (string): The RTF string to convert.
#### Returns
- string: The resulting HTML string.
Example Output
`html
Main symptoms:
Warning in red
`
How to run tests
In your VS Code terminal, run:
`sh
node test
``