rtf-parser-tt 0.5.1

RTF parser with special character support (emdash, smart quotes, etc). Fork of rtf-parser.
Documentation

rtf-parser-tt

Crates.io Documentation License

RTF parser with special character support. Fork of rtf-parser by @d0rianb.

Why rtf-parser-tt

rtf-parser-tt began as a fork of rtf-parser to preserve special characters such as em dashes and smart quotes. That support was merged into rtf-parser and released in version 0.4.3. rtf-parser-tt is maintained independently, with a focus on reliable handling of real-world documents: RtfDocument::try_from and RtfDocument::from_filepath return an error for malformed input instead of causing a panic.

Support

If you find this crate useful, consider supporting development:

Installation

[dependencies]

rtf-parser-tt = "0.5"

What's Added

Control Word Unicode Character
\emdash U+2014 —
\endash U+2013 –
\bullet U+2022 •
\lquote U+2018 '
\rquote U+2019 '
\ldblquote U+201C "
\rdblquote U+201D "
\tab U+0009 (tab)
\line U+000A (newline)

Usage

use rtf_parser_tt::RtfDocument;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let rtf = r#"{\rtf1\ansi Hello\emdash world}"#;
    let doc = RtfDocument::try_from(rtf)?;
    let text = doc.get_text();
    assert!(text.contains("—"));
    Ok(())
}

API

The API is identical to rtf-parser. See the original documentation for full details.

Key types:

  • RtfDocument - Parsed RTF document
  • Lexer - Tokenizes RTF input
  • Parser - Converts tokens to document
  • StyleBlock - Text with formatting info
  • Painter - Text style (bold, italic, etc.)
  • Paragraph - Layout info (alignment, spacing)

License

MIT License - same as upstream.

Credits