rtf-to-html
Convert RTF documents to clean, semantic HTML.
Support
If you find this crate useful, consider supporting development:
Features
- Converts RTF to semantic HTML (
<strong>,<em>,<u>) - Paragraph structure preserved with
<p>tags - XSS-safe output (HTML entities escaped)
- Plain text extraction (strips all formatting)
- Zero unsafe code
Installation
[]
= "0.1"
Usage
Convert RTF to HTML
use rtf_to_html;
let rtf = br#"{\rtf1\ansi\deff0 {\b Bold} and {\i italic} text}"#;
let html = rtf_to_html.unwrap;
// Output: <p><strong>Bold</strong> and <em>italic</em> text</p>
Extract Plain Text
use rtf_to_plain_text;
let rtf = br#"{\rtf1\ansi\deff0 Hello World}"#;
let text = rtf_to_plain_text.unwrap;
// Output: Hello World
Supported Formatting
| RTF | HTML Output |
|---|---|
\b (bold) |
<strong> |
\i (italic) |
<em> |
\ul (underline) |
<u> |
\par (paragraph) |
<p> |
Limitations
This crate focuses on basic text formatting. The following are not currently supported:
- Hyperlinks (
\fieldwith HYPERLINK) - Embedded images or objects
- Tables
- Font sizes and colors
- Lists (numbered/bulleted)
Contributions welcome!
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Credits
Built by TwelveTake Studios. Uses the rtf-parser crate for RTF parsing.