Skip to main content

Crate rtf_parser_tt

Crate rtf_parser_tt 

Source
Expand description

§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 WordUnicodeCharacter
\emdashU+2014—
\endashU+2013–
\bulletU+2022•
\lquoteU+2018’
\rquoteU+2019’
\ldblquoteU+201C“
\rdblquoteU+201D“
\tabU+0009(tab)
\lineU+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

Re-exports§

pub use document::*;
pub use header::*;
pub use lexer::*;
pub use paragraph::*;
pub use parser::*;
pub use tokens::*;

Modules§

document
header
lexer
paragraph
parser
tokens

Macros§

include_test_file
recursive_tokenize
recursive_tokenize_with_init