#escaping #quote #ellipsis #latex #spaces #rules

bin+lib crowbook-text-processing

Provides some utilities functions for escaping text (HTML/LaTeX) and formatting it according to typographic rules (smart quotes, ellipsis, french typograhic rules)

18 releases (3 stable)

1.1.1 Aug 3, 2023
1.1.0 Jul 29, 2023
1.0.0 Feb 10, 2020
0.2.8 Nov 11, 2019
0.2.2 Oct 21, 2016

#153 in Text processing

Download history 48/week @ 2023-11-20 12/week @ 2023-11-27 17/week @ 2023-12-04 5/week @ 2023-12-11 4/week @ 2023-12-25 11/week @ 2024-01-01 35/week @ 2024-01-08 6/week @ 2024-01-15 26/week @ 2024-01-29 30/week @ 2024-02-05 48/week @ 2024-02-12 107/week @ 2024-02-19 148/week @ 2024-02-26 43/week @ 2024-03-04

347 downloads per month
Used in 3 crates

MPL-2.0 license

62KB
1K SLoC

See the full library documentation on Docs.rs.

Provides some utilities functions for escaping text (to HTML or LaTeX) and formatting it according to typographic rules (smart quotes, ellipsis, french rules for non-breaking spaces).

These functions were originally written for Crowbook, but have been published on a separate crate and under a less restrictive license (MPL instead of LGPL) so they can be used in other projects.

Usage

Just add this line in the dependencies section of your Cargo.toml file:

[dependencies]
crowbook-text-processing = "0.2"

Example

use crowbook_text_processing::{FrenchFormatter, clean, escape};

let s = " Some  string with  too much   whitespaces & around 1% \
         characters that might cause trouble to HTML or LaTeX.";
// Remove unnecessary whitespaces (but doesn't trim as it can have meaning)
let new_s = clean::whitespaces(s);
// Escape forHTML
println!("for HTML: {}", escape::html(new_s.clone()));
// Escape for LaTeX
println!("for LaTeX: {}", escape::tex(new_s));

// Replace quotes with typographic quotation marks
let s = r#"Some "quoted string" and 'another one'."#;
let new_s = clean::quotes(s);
assert_eq!(&new_s, "Some “quoted string” and ‘another one’.");

// Replace three consecutive dots with ellipsis character
let s = clean::ellipsis("Foo...");
assert_eq!(&s, "Foo…");

// Format whitespaces according to french typographic rules, using
// the appropriate non-breaking spaces where needed
let s = " Une chaîne en français ! On voudrait un résultat \
         « typographiquement correct ».";
let french = FrenchFormatter::new();
println!("for text: {}", french.format(s));
println!("for LaTeX: {}", escape::tex(french.format_tex(s)));

License

This is free software, published under the Mozilla Public License, version 2.0.

ChangeLog

See the ChangeLog file.

Dependencies

~2.1–3MB
~53K SLoC