text_to_sounds/lib.rs
1//! # text-to-sounds
2//!
3//! Text-to-sounds parsing tool.
4//!
5//! ## Overview
6//!
7//! The library has functions (`parse`, `serialize`) to parse text (`AsRef<str>`) to `Vec<Sound>` and serialize `Vec<Sound>` to `String`. `Sound` struct has information about English sound. `highlight` function adds `html` tags to text that can be used to highlight sounds in the browser via `css`.
8//!
9//! ```rust
10//! use uuid::Uuid;
11//!
12//! // English sound kinds
13//! enum SoundKind {
14//! Ptk,
15//! Th,
16//! W,
17//! V,
18//! Ng,
19//! Ch,
20//! Dj,
21//! Undefined,
22//! }
23//!
24//! // Struct of the sound
25//! pub struct Sound {
26//! id: Uuid,
27//! kind: SoundKind,
28//! text: String,
29//! }
30//! ```
31//!
32//! ## Installation
33//!
34//! In order to use this crate, you have to add it under `[dependencies]` to your `Cargo.toml`:
35//!
36//! ```toml
37//! [dependencies]
38//! text-to-sounds = "1.1.1"
39//! ```
40//!
41//! ## Examples
42//!
43//! ```rust
44//! use text_to_sounds::{parse, serialize, highlight, SoundKind, Sound};
45//!
46//! let sounds = vec![
47//! Sound::new(SoundKind::Th, String::from("Th")),
48//! Sound::new(SoundKind::Undefined, String::from("e")),
49//! Sound::new(SoundKind::Undefined, String::from(" ")),
50//! Sound::new(SoundKind::Ptk, String::from("t")),
51//! Sound::new(SoundKind::Undefined, String::from("e")),
52//! Sound::new(SoundKind::Undefined, String::from("x")),
53//! Sound::new(SoundKind::Ptk, String::from("t")),
54//! Sound::new(SoundKind::Undefined, String::from(" ")),
55//! Sound::new(SoundKind::Dj, String::from("j")),
56//! Sound::new(SoundKind::Undefined, String::from("u")),
57//! Sound::new(SoundKind::Undefined, String::from("s")),
58//! Sound::new(SoundKind::Ptk, String::from("t")),
59//! Sound::new(SoundKind::Undefined, String::from(" ")),
60//! Sound::new(SoundKind::Undefined, String::from("i")),
61//! Sound::new(SoundKind::Undefined, String::from("n")),
62//! Sound::new(SoundKind::Undefined, String::from(" ")),
63//! Sound::new(SoundKind::Ptk, String::from("c")),
64//! Sound::new(SoundKind::Undefined, String::from("a")),
65//! Sound::new(SoundKind::Undefined, String::from("s")),
66//! Sound::new(SoundKind::Undefined, String::from("e")),
67//! ];
68//!
69//! // parse
70//! assert_eq!(parse("The text just in case"), sounds);
71//!
72//! // serialize
73//! assert_eq!(serialize(sounds), "The text just in case");
74//!
75//! // highlight
76//! assert_eq!(highlight("The text just in case"), "<span class='Th'>Th</span>e <span class='Ptk'>t</span>ex<span class='Ptk'>t</span> <span class='Dj'>j</span>us<span class='Ptk'>t</span> in <span class='Ptk'>c</span>ase".to_string());
77//! ```
78//!
79//! Also, you can consider tests inside the files.
80
81mod highlighter;
82mod parser;
83mod scanner;
84mod serializer;
85mod sound;
86mod wasm;
87
88pub use crate::highlighter::highlight;
89pub use crate::parser::parse;
90pub use crate::serializer::serialize;
91pub use crate::sound::{Sound, SoundKind};
92pub use crate::wasm::highlight_wasm;