### Usage example for all Source: https://docs.rs/unidown/latest/unidown/fn.all.html Demonstrates the output of the all function when provided with the input string 'Text'. ```rust assert_eq!( unidown::all("Text"), " ๐˜›๐˜ฆ๐˜น๐˜ต ๐“๐ž๐ฑ๐ญ ๐šƒ๐šŽ๐šก๐š Tฬถeฬถxฬถtฬถ ๐‘ป๐’†๐’™๐’• ๐’ฏโ„ฏ๐“๐“‰ ๐“ฃ๐“ฎ๐”๐“ฝ โ“‰โ“”โ“งโ“ฃ ๐˜›ฬถ๐˜ฆฬถ๐˜นฬถ๐˜ตฬถ ๐“ฬถ๐žฬถ๐ฑฬถ๐ญฬถ ๐‘ปฬถ๐’†ฬถ๐˜นฬถ๐’•ฬถ ๐šƒฬถ๐šŽฬถ๐šกฬถ๐šฬถ ๐”—๐”ข๐”ต๐”ฑ ๐•ฟ๐–Š๐–๐–™ ๐•‹๐•–๐•ฉ๐•ฅ ", ); ``` -------------------------------- ### Example usage of unidown::demo with assertion Source: https://docs.rs/unidown/latest/unidown/fn.demo.html Shows how to call `unidown::demo` with a sample string and asserts the expected output. The output is a multi-line table with columns for input, result, and style, demonstrating various text formatting styles. ```rust assert_eq!( unidown::demo("Your text here"), "\ | Input | Result | Style |\n\ |----------------------------------|----------------|--------------------|\n\ | `` *Your text here* `` | ๐˜ ๐˜ฐ๐˜ถ๐˜ณ ๐˜ต๐˜ฆ๐˜น๐˜ต ๐˜ฉ๐˜ฆ๐˜ณ๐˜ฆ | italic |\n\ | `` **Your text here** `` | ๐˜๐จ๐ฎ๐ซ ๐ญ๐ž๐ฑ๐ญ ๐ก๐ž๐ซ๐ž | bold |\n\ | `` `Your text here` `` | ๐šˆ๐š˜๐šž๐š› ๐š๐šŽ๐šก๐š ๐š‘๐šŽ๐š›๐šŽ | monospace |\n\ | `` ~~Your text here~~ `` | Yฬถoฬถuฬถrฬถ ฬถtฬถeฬถxฬถtฬถ ฬถhฬถeฬถrฬถeฬถ | strike |\n\ | `` ***Your text here*** `` | ๐’€๐’๐’–๐’“ ๐’•๐’†๐’™๐’• ๐’‰๐’†๐’“๐’† | bold-italic |\n\ | `` *`Your text here`* `` | ๐’ดโ„ด๐“Š๐“‡ ๐“‰โ„ฏ๐“๐“‰ ๐’ฝโ„ฏ๐“‡โ„ฏ | script |\n\ | `` **`Your text here`** `` | ๐“จ๐“ธ๐“พ๐“ป ๐“ฝ๐“ฎ๐”๐“ฝ ๐“ฑ๐“ฎ๐“ป๐“ฎ | bold-script |\n\ | `` ***`Your text here`*** `` | โ“Žโ“žโ“คโ“ก โ“ฃโ“”โ“งโ“ฃ โ“—โ“”โ“กโ“” | circled |\n\ | `` ~~*Your text here*~~ `` | ๐˜ ฬถ๐˜ฐฬถ๐˜ถฬถ๐˜ณฬถ ฬถ๐˜ตฬถ๐˜ฆฬถ๐˜นฬถ๐˜ตฬถ ฬถ๐˜ฉฬถ๐˜ฆฬถ๐˜ณฬถ๐˜ฆฬถ | strike-italic |\n\ | `` ~~**Your text here**~~ `` | ๐˜ฬถ๐จฬถ๐ฎฬถ๐ซฬถ ฬถ๐ญฬถ๐žฬถ๐ฑฬถ๐ญฬถ ฬถ๐กฬถ๐žฬถ๐ซฬถ๐žฬถ | strike-bold |\n\ | `` ~~***Your text here***~~ `` | ๐’€ฬถ๐’ฬถ๐’–ฬถ๐’“ฬถ ฬถ๐’•ฬถ๐’†ฬถ๐’™ฬถ๐’•ฬถ ฬถ๐’‰ฬถ๐’†ฬถ๐’“ฬถ๐’†ฬถ | strike-bold-italic |\n\ | `` ~~`Your text here`~~ `` | ๐šˆฬถ๐š˜ฬถ๐šžฬถ๐š›ฬถ ฬถ๐šฬถ๐šŽฬถ๐šกฬถ๐šฬถ ฬถ๐š‘ฬถ๐šŽฬถ๐š›ฬถ๐šŽฬถ | strike-monospace |\n\ | `` ~~*`Your text here`*~~ `` | ๐”œ๐”ฌ๐”ฒ๐”ฏ ๐”ฑ๐”ข๐”ต๐”ฑ ๐”ฅ๐”ข๐”ฏ๐”ข | fraktur |\n\ | `` ~~**`Your text here`**~~ `` | ๐–„๐–”๐–š๐–— ๐–™๐–Š๐–๐–™ ๐–๐–Š๐–—๐–Š | bold-fraktur |\n\ | `` ~~***`Your text here`***~~ `` | ๐•๐• ๐•ฆ๐•ฃ ๐•ฅ๐•–๐•ฉ๐•ฅ ๐•™๐•–๐•ฃ๐•– | double-struck |\n\n\ " ); ``` -------------------------------- ### Start Tag Logic Source: https://docs.rs/unidown/latest/src/unidown/lib.rs.html Determines the start of an HTML tag, handling paragraph and heading structures. ```rust fn start_tag(&mut self, tag: Tag<'a>) -> Result<(), W::Error> { match tag { Tag::Paragraph => { if self.end_newline { Ok(()) } else { self.write("\n") } } Tag::Heading { level, id: _, classes: _, attrs: _, } => { if self.end_newline { ``` -------------------------------- ### Example usage with assertions for Markdown-to-Unicode conversion Source: https://docs.rs/unidown/latest/unidown/fn.convert.html Illustrates usage of `convert` in a test with a table of markdown and expected Unicode strings, asserting equality. Covers emphasis, strong, code, strike, and math expressions. ```rust for (markdown, unicode) in &[ ("*Emphasis*\n\n", "๐˜Œ๐˜ฎ๐˜ฑ๐˜ฉ๐˜ข๐˜ด๐˜ช๐˜ด\n\n"), ("**Strong**\n\n", "๐’๐ญ๐ซ๐จ๐ง๐ \n\n"), ("`Code`\n\n", "๐™ฒ๐š˜๐š๐šŽ\n\n"), ("~~Strike~~\n\n", "Sฬถtฬถrฬถiฬถkฬถeฬถ\n\n"), ("***Emphasis strong***\n\n", "๐‘ฌ๐’ฎ๐’ฎ๐’ฏ๐’ถ๐“ˆ๐’พ๐“ˆ ๐’”๐’•๐’“๐’๐’๐’ˆ\n\n"), ("***Emphasis* strong**\n\n", "๐‘ฌ๐’ฎ๐’ฎ๐’ฏ๐’ถ๐“ˆ๐’พ๐“ˆ ๐’๐ญ๐ซ๐จ๐ง๐ \n\n"), ("***Strong** emphasis*\n\n", "๐‘ฌ๐’ฎ๐’ฎ๐’ฏ๐’ถ๐“ˆ๐’พ๐“ˆ ๐’”๐’•๐’“๐’๐’๐’ˆ\n\n"), ("*`Emphasis code`*\n\n", "โ„ฐ๐“‚๐“…๐’ฝ๐’ถ๐“ˆ๐’พ๐“ˆ ๐’ธโ„ด๐’นโ„ฏ\n\n"), ("**`Strong code`**\n\n", "๐“๐“ฝ๐“ป๐“ธ๐“ท๐“ฐ ๐“ฌ๐“ธ๐“ญ๐“ฎ\n\n"), ("***`Emphasis strong code`***\n\n", "โ’บโ“œโ“Ÿโ“—โ“โ“ขโ“˜โ“ข โ“ขโ“ฃโ“กโ“žโ“โ“– โ“’โ“žโ““โ“”\n\n"), ("~~*Strike emphasis*~~\n\n", "๐˜šฬถ๐˜ตฬถ๐˜ณฬถ๐˜ชฬถ๐˜ฌฬถ๐˜ฆฬถ ฬถ๐˜ฆฬถ๐˜ฎฬถ๐˜ฑฬถ๐˜ฉฬถ๐˜ขฬถ๐˜ดฬถ๐˜ชฬถ๐˜ดฬถ\n\n"), ("~~**Strike strong**~~\n\n", "๐’ฬถ๐ญฬถ๐ซฬถ๐ขฬถ๐คฬถ๐คฬถ๐žฬถ ฬถ๐ฌฬถ๐ญฬถ๐ซฬถ๐จฬถ๐งฬถ๐ ฬถ\n\n"), ("~~***Strike emphasis strong***~~\n\n", "๐‘บฬถ๐’•ฬถ๐’“ฬถ๐’Šฬถ๐’Œฬถ๐’†ฬถ ฬถ๐’†ฬถ๐’Žฬถ๐’‘ฬถ๐’‰ฬถ๐’‚ฬถ๐’”ฬถ๐’Šฬถ๐’”ฬถ ฬถ๐’”ฬถ๐’•ฬถ๐’“ฬถ๐’ฬถ๐’ฬถ๐’ˆฬถ\n\n"), ("~~`Strike code`~~\n\n", "ร‘ฮถ ๐™จฬถ ฬถ ๐™›ฬถ ๐™—ฬถ ๐™จฬถ ๐™šฬถ ฬถ ๐™จฬถ\n\n"), ("~~*`Strike emphasis code`*~~\n\n", "๐”–๐”ฑ๐”ฏ๐”ฆ๐”จ๐”ข ๐”ข๐”ช๐”ญ๐”ฅ๐”ž๐”ฐ๐”ฆ๐”ฐ ๐” ๐”ฌ๐”ก๐”ข\n\n"), ("~~**`Strike strong code`**~~\n\n", "๐•พ๐–™๐–—๐–Ž๐–๐–Š ๐–˜๐–™๐–—๐–”๐–“๐–Œ ๐–ˆ๐–”๐–‰๐–Š\n\n"), ("~~***`Strike emphasis strong code`***~~\n\n", "๐•Š๐•ฅ๐•ฃ๐•š๐•œ๐•– ๐•–๐•ž๐•ก๐•™๐•’๐•ค๐•š๐•ค ๐•ค๐•ฅ๐•ฃ๐• ๐•Ÿ๐•˜ ๐•”๐• ๐••๐•–\n\n"), ("$f(x)=x^2$", "$f(x)=x^2$\n\n"), ("$$f(x)=x^2$$", "$$f(x)=x^2$$\n\n"), ] { assert_eq!(unidown::convert(markdown), *unicode); } ``` -------------------------------- ### Convert Markdown to Unicode with unidown::convert Source: https://docs.rs/unidown/latest/unidown/index.html Example usage of the unidown::convert function, demonstrating conversion of Markdown text with emphasis, strong, strong emphasis, strike, and code to Unicode. The output shows the converted Unicode string. ```rust assert_eq!( unidown::convert("\ Here is some *emphasis*, **strong**, ***strong emphasis***, ~~strike~~, \ and `code` text.\n\n\ "), "Here is some ๐˜ฆ๐˜ฎ๐˜ฑ๐˜ฉ๐˜ข๐˜ด๐˜ช๐˜ด, ๐ฌ๐ญ๐ซ๐จ๐ง๐ , ๐’”๐’•๐’“๐’๐’๐’ˆ ๐’†๐’Ž๐’‘๐’‰๐’‚๐’”๐’Š๐’”, sฬถtฬถrฬถiฬถkฬถeฬถ, and ๐šŒ๐š˜๐š๐šŽ text.\n\n", ); ``` -------------------------------- ### all Source: https://docs.rs/unidown Runs all mode of the unidown crate. ```APIDOC ## all ### Description All mode. ### Method Function ### Endpoint `unidown::all` ### Parameters None ### Request Example ```rust unidown::all(); ``` ### Response #### Success Response No return value. #### Response Example ```rust () ``` ``` -------------------------------- ### Generate a demonstration table of styles Source: https://docs.rs/unidown/latest/src/unidown/lib.rs.html The demo function creates a markdown table showing various input syntax patterns and their corresponding Unicode style outputs. ```rust #[allow(clippy::missing_panics_doc)] #[must_use] pub fn demo(s: &str) -> String { let mut t = Veg::table("Input|Result|Style\n-|-|-"); for (syntax, style) in [ ("*", "italic"), ("**", "bold"), ("`", "monospace"), ("~~", "strike"), ("***", "bold-italic"), ("*`", "script"), ("**`", "bold-script"), ("***`", "circled"), ("~~*", "strike-italic"), ("~~**", "strike-bold"), ("~~***", "strike-bold-italic"), ("~~`", "strike-monospace"), ("~~*`", "fraktur"), ("~~**`", "bold-fraktur"), ("~~***`", "double-struck"), ] { let input = format!("{syntax}{s}{}", syntax.chars().rev().collect::()); t.push(Box::new(Row::new( &format!("`` {input} ``"), &convert(&input).replace("\n\n", ""), style, ))); } format!("{}\n", t.markdown().unwrap()) } ``` -------------------------------- ### demo Source: https://docs.rs/unidown Runs a demo mode of the unidown crate. ```APIDOC ## demo ### Description Demo mode. ### Method Function ### Endpoint `unidown::demo` ### Parameters None ### Request Example ```rust unidown::demo(); ``` ### Response #### Success Response No return value. #### Response Example ```rust () ``` ``` -------------------------------- ### Demo mode usage Source: https://docs.rs/unidown/latest/src/unidown/lib.rs.html Shows how to use the unidown::demo function to generate a table of supported Unicode styles for a given input string. ```rust assert_eq!( unidown::demo("Your text here"), "\ | Input | Result | Style |\n\ |----------------------------------|----------------|--------------------|\n\ | `` *Your text here* `` | ๐˜ ๐˜ฐ๐˜ถ๐˜ณ ๐˜ต๐˜ฆ๐˜น๐˜ต ๐˜ฉ๐˜ฆ๐˜ณ๐˜ฆ | italic |\n\ | `` **Your text here** `` | ๐˜๐จ๐ฎ๐ซ ๐ญ๐ž๐ฑ๐ญ ๐ก๐ž๐ซ๐ž | bold |\n\ | `` `Your text here` `` | ๐šˆ๐š˜๐šž๐š› ๐š๐šŽ๐šก๐š ๐š‘๐šŽ๐˜ณ๐šŽ | monospace |\n\ | `` ~~Your text here~~ `` | Yฬถoฬถuฬถrฬถ ฬถtฬถeฬถxฬถtฬถ ฬถhฬถeฬถrฬถeฬถ | strike |\n\ | `` ***Your text here*** `` | ๐’€๐’๐’–๐’“ ๐’•๐’†๐’˜๐’• ๐’‰๐’†๐’“๐’† | bold-italic |\n\ | `` *`Your text here`* `` | ๐’ดโ„ด๐“Š๐“‡ ๐“‰โ„ฏ๐“๐“‰ ๐’ฝโ„ฏ๐“‡โ„ฏ | script |\n\ | `` **`Your text here`** `` | ๐“จ๐“ธ๐“พ๐“ป ๐“ฝ๐“ฎ๐”๐“ฝ ๐“ฑ๐“ฎ๐“ป๐“ฎ | bold-script |\n" ``` -------------------------------- ### unidown::demo Source: https://docs.rs/unidown/latest/src/unidown/lib.rs.html Returns a formatted table showing how given input text would appear in various Unicode styles, as a demonstration of supported formatting. The output includes columns for input, result, and style. ```APIDOC ## demo ### Description Generates a demo table for a given input text, displaying its Unicode representation in multiple Markdown styles (e.g., bold, italic, code, strikethrough). Returns a newline-separated string formatted as a table. ### Function Signature pub fn demo("Your text here") -> String ### Parameters - **s** (string) - Required - The input text used to demonstrate available styles. ### Returns String - A formatted table with columns for Input, Result, and Style. ### Example ```rust let output = unidown::demo("Your text here"); assert!(output.contains("Your text here")); ``` ``` -------------------------------- ### Function signature: pub fn demo(s: &str) -> String Source: https://docs.rs/unidown/latest/unidown/fn.demo.html Declares the `demo` function, which accepts a string slice and returns a `String`. This is the public API for the demo mode. ```rust pub fn demo(s: &str) -> String ``` -------------------------------- ### convert Source: https://docs.rs/unidown Converts Markdown text to Unicode using the unidown crate. ```APIDOC ## convert ### Description Convert Markdown to Unicode. ### Method Function ### Endpoint `unidown::convert` ### Parameters - **input** (string) - Required - The Markdown text to convert. ### Request Example ```rust let result = unidown::convert("*Emphasis*"); ``` ### Response #### Success Response - **output** (string) - The converted Unicode text. #### Response Example ```rust "๐˜Œ๐˜ฎ๐˜ฑ๐˜ฉ๐˜ข๐˜ด๐˜ช๐˜ด" ``` ``` -------------------------------- ### Apply all Unicode styles Source: https://docs.rs/unidown/latest/src/unidown/lib.rs.html The all function applies every available Unicode style to the provided input string. ```rust assert_eq!( unidown::all("Text"), "\ ๐˜›๐˜ฆ๐˜น๐˜ต\n\ ๐“๐ž๐ฑ๐ญ\n\ ๐šƒ๐šŽ๐šก๐š\n\ Tฬถeฬถxฬถtฬถ\n\ ๐‘ป๐’†๐’™๐’•\n\ ๐’ฏโ„ฏ๐“๐“‰\n\ ๐“ฃ๐“ฎ๐”๐“ฝ\n\ โ“‰โ“”โ“งโ“ฃ\n\ ๐˜›ฬถ๐˜ฆฬถ๐˜นฬถ๐˜ตฬถ\n\ ๐“ฬถ๐žฬถ๐ฑฬถ๐ญฬถ\n\ ๐‘ปฬถ๐’†ฬถ๐’™ฬถ๐ญฬถ\n\ ๐šƒฬถ๐šŽฬถ๐šกฬถ๐šฬถ\n\ ๐”—๐”ข๐”ต๐”ฑ\n\ ๐•ฟ๐–Š๐–๐–™\n\ ๐•‹๐•–๐•ฉ๐•ฅ\n\n\ ", ); ``` ```rust #[must_use] pub fn all(s: &str) -> String { format!( "{}\n", [ "*", "**", "`", "~~", "***", "*`", "**`", "***`", "~~*", "~~**", "~~***", "~~`", "~~*`", "~~**`", "~~***`", ] .iter() .map(|a| { convert(&format!("{a}{s}{}", a.chars().rev().collect::())).replace("\n\n", "\n") }) .collect::() ) } ``` -------------------------------- ### Function signature: pub fn convert(s: &str) -> String Source: https://docs.rs/unidown/latest/unidown/fn.convert.html Shows the signature of the `convert` function, taking a string slice and returning a `String`. This is the API entry point for converting Markdown to Unicode. ```rust pub fn convert(s: &str) -> String ``` -------------------------------- ### all Source: https://docs.rs/unidown/latest/unidown/fn.all.html The `all` function converts a string into all available Unicode text styles, returning a newline-separated string containing each style variant. It is the primary entry point for the unidown library's all-mode conversion. ```APIDOC ## Function: all ### Description Converts a string into all available Unicode text styles, returning a newline-separated string containing each style variant. This is the "all mode" of the unidown library. ### Signature ```rust pub fn all(s: &str) -> String ``` ### Parameters - **s** (`&str`) - Required - The input string to be converted. ### Returns - **String** - A string containing each style variant separated by newlines, with a trailing newline. ### Example ```rust assert_eq!( unidown::all("Text"), "\ ๐˜›๐˜ฆ๐˜น๐˜ต\n\ ๐“๐ž๐ฑ๐ญ\n\ ๐šƒ๐šŽ๐šก๐š\n\ Tฬถeฬถxฬถtฬถ\n\ ๐‘ป๐’†๐’™๐’•\n\ ๐’ฏโ„ฏ๐“๐“‰\n\ ๐“ฃ๐“ฎ๐”๐“ฝ\n\ โ“‰โ“”โ“งโ“ฃ\n\ ๐˜›ฬถ๐˜ฆฬถ๐˜นฬถ๐˜ตฬถ\n\ ๐“ฬถ๐žฬถ๐ฑฬถ๐ญฬถ\n\ ๐‘ปฬถ๐’†ฬถ๐’™ฬถ๐’•ฬถ\n\ ๐šƒฬถ๐šŽฬถ๐šกฬถ๐šฬถ\n\ ๐”—๐”ข๐”ต๐”ฑ\n\ ๐•ฟ๐–Š๐–๐–™\n\ ๐•‹๐•–๐•ฉ๐•ฅ\n\n\ ", ); ``` ``` -------------------------------- ### Function signature for all Source: https://docs.rs/unidown/latest/unidown/fn.all.html The signature of the all function, which accepts a string slice and returns a String. ```rust pub fn all(s: &str) -> String ``` -------------------------------- ### unidown::convert Source: https://docs.rs/unidown/latest/src/unidown/lib.rs.html Converts a Markdown string into Unicode text, applying formatting such as emphasis, bold, code, strikethrough, and combinations. Returns the converted Unicode string. ```APIDOC ## convert ### Description Converts Markdown string to Unicode equivalents for supported styles. Does not convert math formulas ($...$), preserving them as-is. ### Function Signature pub fn convert(s: &str) -> String ### Parameters - **s** (str) - Required - The Markdown string to be converted to Unicode. ### Returns - **String** - The Unicode-converted text with styles applied. ### Example ```rust let result = unidown::convert("**Bold** and *italic*"); ``` ``` -------------------------------- ### push_unicode Source: https://docs.rs/unidown/latest/unidown/fn.push_unicode.html Iterate over an iterator of Events, generate Unicode for each Event, and push it to a String. Panics if unable to write to the given string. ```APIDOC ## push_unicode ### Description Iterate over an `Iterator` of `Event`s, generate Unicode for each `Event`, and push it to a `String`. ### Function Signature ```rust pub fn push_unicode<'a, I>(s: &mut String, iter: I) where I: Iterator>, ``` ### Parameters - **s** (`&mut String`) - The string to which the generated Unicode will be pushed. - **iter** (`I`) - An iterator over `Event`s. Each event is processed to generate Unicode. ### Panics Panics if not able to write to the given `&mut String`. ``` -------------------------------- ### Text Styling Logic Source: https://docs.rs/unidown/latest/src/unidown/lib.rs.html Handles text styling based on strong and emphasis flags, mapping characters to specific alphabets. ```rust let alphabet: &HashMap = match (self.strong, self.emphasis) { (true, true) => &BOLD_ITALIC_C, (true, false) => &BOLD_C, (false, true) => &ITALIC_C, (false, false) => ®ULAR_C, }; let u = t .chars() .map(|c| { if let Some(i) = ALL_I.get(&c) { alphabet[i] } else { c } }) .collect::(); let u = if self.strike { strike(&u) } else { u }; self.write(&u)?; self.end_newline = text.ends_with('\n'); } } ``` -------------------------------- ### Push Unicode events to a String Source: https://docs.rs/unidown/latest/src/unidown/lib.rs.html Iterates over an iterator of Events, generates Unicode for each, and pushes the result to a String. Panics if writing to the string fails. ```rust pub fn push_unicode<'a, I>(s: &mut String, iter: I) where I: Iterator>, { write_unicode_fmt(s, iter).unwrap(); } ``` -------------------------------- ### Crate Imports Source: https://docs.rs/unidown/latest/src/unidown/lib.rs.html Required imports for the Unidown library, including clap, pulldown-cmark for Markdown parsing, and utility crates for character escaping and data structures. ```rust use { clap::ValueEnum, pulldown_cmark::{ Alignment, CowStr, Event, Event::{ Code, DisplayMath, End, FootnoteReference, HardBreak, Html, InlineHtml, InlineMath, Rule, SoftBreak, Start, TaskListMarker, Text, }, HeadingLevel, Options, Parser, Tag, TagEnd, }, pulldown_cmark_escape::{ FmtWriter, IoWriter, StrWrite, escape_href, escape_html, escape_html_body_text, }, std::{collections::HashMap, fmt, io, sync::LazyLock}, veg::Veg, }; ``` -------------------------------- ### convert(s: &str) -> String Source: https://docs.rs/unidown/latest/unidown/fn.convert.html Converts Markdown text to Unicode. This function processes Markdown formatting such as emphasis, strong, code, strike, and their combinations, returning the Unicode equivalent. ```APIDOC ## Function: convert ### Description Converts Markdown text to Unicode. This function processes Markdown formatting such as emphasis, strong, code, strike, and their combinations, returning the Unicode equivalent. ### Signature pub fn convert(s: &str) -> String ### Parameters - **s** (&str) - Required - The Markdown string to convert. ### Return Value - **String** - The Unicode-converted string. ### Example ```rust for (markdown, unicode) in &[ ("*Emphasis*\n\n", "๐˜Œ๐˜ฎ๐˜ฑ๐˜ฉ๐˜ข๐˜ด๐˜ช๐˜ด\n\n"), ("**Strong**\n\n", "๐’๐ญ๐ซ๐จ๐ง๐ \n\n"), ("`Code`\n\n", "๐™ฒ๐š˜๐š๐šŽ\n\n"), ("~~Strike~~\n\n", "Sฬถtฬถrฬถiฬถkฬถeฬถ\n\n"), ("***Emphasis strong***\n\n", "๐‘ฌ๐’Ž๐’‘๐’‰๐’‚๐’”๐’Š๐’” ๐’”๐’•๐’“๐’๐’๐’ˆ\n\n"), ("***Emphasis* strong**\n\n", "๐‘ฌ๐’Ž๐’‘๐’‰๐’‚๐’”๐’Š๐’” ๐ฌ๐ญ๐ซ๐จ๐ง๐ \n\n"), ("***Strong** emphasis*\n\n", "๐‘บ๐’•๐’“๐’๐’๐’ˆ ๐˜ฆ๐˜ฎ๐˜ฑ๐˜ฉ๐˜ข๐˜ด๐˜ช๐˜ด\n\n"), ("*`Emphasis code`*\n\n", "โ„ฐ๐“‚๐“…๐’ฝ๐’ถ๐“ˆ๐’พ๐“ˆ ๐’ธโ„ด๐’นโ„ฏ\n\n"), ("**`Strong code`**\n\n", "๐“ข๐“ฝ๐“ป๐“ธ๐“ท๐“ฐ ๐“ฌ๐“ธ๐“ญ๐“ฎ\n\n"), ("***`Emphasis strong code`***\n\n", "โ’บโ“œโ“Ÿโ“—โ“โ“ขโ“˜โ“ข โ“ขโ“ฃโ“กโ“žโ“โ“– โ“’โ“žโ““โ“”\n\n"), ("~~*Strike emphasis*~~\n\n", "๐˜šฬถ๐˜ตฬถ๐˜ณฬถ๐˜ชฬถ๐˜ฌฬถ๐˜ฆฬถ ฬถ๐˜ฆฬถ๐˜ฎฬถ๐˜ฑฬถ๐˜ฉฬถ๐˜ขฬถ๐˜ดฬถ๐˜ชฬถ๐˜ดฬถ\n\n"), ("~~**Strike strong**~~\n\n", "๐’ฬถ๐ญฬถ๐ซฬถ๐ขฬถ๐คฬถ๐žฬถ ฬถ๐ฌฬถ๐ญฬถ๐ซฬถ๐จฬถ๐งฬถ๐ ฬถ\n\n"), ("~~***Strike emphasis strong***~~\n\n", "๐‘บฬถ๐’•ฬถ๐’“ฬถ๐’Šฬถ๐’Œฬถ๐’†ฬถ ฬถ๐’†ฬถ๐’Žฬถ๐’‘ฬถ๐’‰ฬถ๐’‚ฬถ๐’”ฬถ๐’Šฬถ๐’”ฬถ ฬถ๐’”ฬถ๐’•ฬถ๐’“ฬถ๐’ฬถ๐’ฬถ๐’ˆฬถ\n\n"), ("~~`Strike code`~~\n\n", "๐š‚ฬถ๐šฬถ๐š›ฬถ๐š’ฬถ๐š”ฬถ๐šŽฬถ ฬถ๐šŒฬถ๐š˜ฬถ๐šฬถ๐šŽฬถ\n\n"), ("~~*`Strike emphasis code`*~~\n\n", "๐”–๐”ฑ๐”ฏ๐”ฆ๐”จ๐”ข ๐”ข๐”ช๐”ญ๐”ฅ๐”ž๐”ฐ๐”ฆ๐”ฐ ๐” ๐”ฌ๐”ก๐”ข\n\n"), ("~~**`Strike strong code`**~~\n\n", "๐•พ๐–™๐–—๐–Ž๐–๐–Š ๐–˜๐–™๐–—๐–”๐–“๐–Œ ๐–ˆ๐–”๐–‰๐–Š\n\n"), ("~~***`Strike emphasis strong code`***~~\n\n", "๐•Š๐•ฅ๐•ฃ๐•š๐•œ๐•– ๐•–๐•ž๐•ก๐•™๐•’๐•ค๐•š๐•ค ๐•ค๐•ฅ๐•ฃ๐• ๐•Ÿ๐•˜ ๐•”๐• ๐••๐•–\n\n"), ("$f(x)=x^2$", "$f(x)=x^2$\n\n"), ("$$f(x)=x^2$$", "$$f(x)=x^2$$\n\n"), ] { assert_eq!(unidown::convert(markdown), *unicode); } ``` ``` -------------------------------- ### Structural Element Handling Source: https://docs.rs/unidown/latest/src/unidown/lib.rs.html Handles various structural elements like HTML, breaks, rules, footnotes, task lists, and math blocks. ```rust Html(html) | InlineHtml(html) => { self.write(&html)?; } SoftBreak => { self.write_newline()?; } HardBreak => { self.write("\n")?; } Rule => { if !self.end_newline { self.write("\n")?; } self.write("---\n\n")?; } FootnoteReference(name) => { let len = self.numbers.len() + 1; let number = *self.numbers.entry(name.clone()).or_insert(len); write!(&mut self.writer, "[{number}][^")?; escape_html(&mut self.writer, &name)?; self.write("]")?; } TaskListMarker(true) => { self.write("โ€ข [X] ")?; } TaskListMarker(false) => { self.write("โ€ข [ ] ")?; } InlineMath(text) => { self.write("$")?; escape_html(&mut self.writer, &text)?; self.write("$")?; } DisplayMath(text) => { self.write("$$")?; escape_html(&mut self.writer, &text)?; self.write("$$")?; } } } if !self.end_newline { self.write("\n")?; } Ok(()) ``` -------------------------------- ### pulldown-cmark License Notice Source: https://docs.rs/unidown/latest/src/unidown/lib.rs.html The MIT license notice required for the modified copies of code from the pulldown-cmark crate. ```text The MIT License Copyright 2015 Google Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ``` -------------------------------- ### write_unicode_fmt Source: https://docs.rs/unidown/latest/unidown/fn.write_unicode_fmt.html Iterate over an `Iterator` of `Event`s, generate Unicode for each `Event`, and write it into a Unicode-accepting buffer or stream. Returns an error if not able to write to the given writer. ```APIDOC ## write_unicode_fmt ### Description Iterate over an `Iterator` of `Event`s, generate Unicode for each `Event`, and write it into a Unicode-accepting buffer or stream. ### Signature ```rust pub fn write_unicode_fmt<'a, I, W>(writer: W, iter: I) -> Result where I: Iterator>, W: Write, ``` ### Parameters - **writer** (`W`) - Required - The Unicode-accepting buffer or stream to write the generated Unicode to. - **iter** (`I`) - Required - An iterator of `Event`s to process and write. ### Errors Returns an error if not able to write to the given writer. ``` -------------------------------- ### Write Unicode events to a formatter Source: https://docs.rs/unidown/latest/src/unidown/lib.rs.html Iterates over an iterator of Events, generates Unicode for each, and writes the output to a Unicode-accepting formatter. Returns an error if writing fails. ```rust pub fn write_unicode_fmt<'a, I, W>(writer: W, iter: I) -> fmt::Result where I: Iterator>, W: fmt::Write, { UnicodeWriter::new(iter, FmtWriter(writer)).run() } ``` -------------------------------- ### Write Unicode events to an I/O stream Source: https://docs.rs/unidown/latest/src/unidown/lib.rs.html Iterates over an iterator of Events, generates Unicode for each, and writes the output to an I/O stream. Returns an error if writing fails. ```rust pub fn write_unicode_io<'a, I, W>(writer: W, iter: I) -> io::Result<()> where I: Iterator>, W: io::Write, { UnicodeWriter::new(iter, IoWriter(writer)).run() } ``` -------------------------------- ### Static Character Mapping Source: https://docs.rs/unidown/latest/src/unidown/lib.rs.html Static LazyLock HashMaps used to map characters to their index within the defined Unicode alphabets, facilitating character transformation. ```rust static REGULAR_I: LazyLock> = LazyLock::new(|| c2i(REGULAR)); static BOLD_I: LazyLock> = LazyLock::new(|| c2i(BOLD)); static ITALIC_I: LazyLock> = LazyLock::new(|| c2i(ITALIC)); static BOLD_ITALIC_I: LazyLock> = LazyLock::new(|| c2i(BOLD_ITALIC)); static MONO_I: LazyLock> = LazyLock::new(|| c2i(MONO)); static CURSIVE_I: LazyLock> = LazyLock::new(|| c2i(CURSIVE)); static BOLD_CURSIVE_I: LazyLock> = LazyLock::new(|| c2i(BOLD_CURSIVE)); static FRAKTUR_I: LazyLock> = LazyLock::new(|| c2i(FRAKTUR)); static BOLD_FRAKTUR_I: LazyLock> = LazyLock::new(|| c2i(BOLD_FRAKTUR)); static DOUBLE_I: LazyLock> = LazyLock::new(|| c2i(DOUBLE)); static CIRCLE_I: LazyLock> = LazyLock::new(|| c2i(CIRCLE)); static ALL_I: LazyLock> = LazyLock::new(|| { REGULAR_I .iter() .chain(BOLD_I.iter()) .chain(ITALIC_I.iter()) .chain(BOLD_ITALIC_I.iter()) .chain(MONO_I.iter()) .chain(CURSIVE_I.iter()) .chain(BOLD_CURSIVE_I.iter()) .chain(FRAKTUR_I.iter()) .chain(BOLD_FRAKTUR_I.iter()) .chain(DOUBLE_I.iter()) .chain(CIRCLE_I.iter()) .map(|(c, i)| (*c, *i)) .collect() }); ``` -------------------------------- ### Convert Text to Unicode Style Source: https://docs.rs/unidown/latest/unidown/enum.Style.html The convert method applies the selected Unicode style to a given string slice. ```rust assert_eq!( unidown::Style::Fraktur.convert("Your text here"), "๐”œ๐”ฌ๐”ฒ๐”ฏ ๐”ฑ๐”ข๐”ต๐”ฑ ๐”ฅ๐”ข๐”ฏ๐”ข\n\n", ); ``` -------------------------------- ### Process raw text Source: https://docs.rs/unidown/latest/src/unidown/lib.rs.html Consumes events until the corresponding end tag is reached, used primarily for generating content for attributes like alt. ```rust 975 fn raw_text(&mut self) -> Result<(), W::Error> { 976 let mut nest = 0; 977 while let Some(event) = self.iter.next() { 978 match event { 979 Start(_) => nest += 1, 980 End(_) => { 981 if nest == 0 { 982 break; 983 } 984 nest -= 1; 985 } 986 Html(_) => {} 987 InlineHtml(text) | Code(text) | Text(text) => { 988 // Don't use escape_html_body_text here. 989 // The output of this function is used in the `alt` attribute. 990 escape_html(&mut self.writer, &text)?; 991 self.end_newline = text.ends_with('\n'); 992 } 993 SoftBreak | HardBreak | Rule => { 994 self.write(" ")?; 995 } 996 FootnoteReference(name) => { 997 let len = self.numbers.len() + 1; 998 let number = *self.numbers.entry(name).or_insert(len); 999 write!(&mut self.writer, "[{number}]")?; 1000 } 1001 TaskListMarker(true) => self.write("[x]")?, 1002 TaskListMarker(false) => self.write("[ ]")?, 1003 InlineMath(text) => { 1004 self.write("$")?; 1005 escape_html(&mut self.writer, &text)?; 1006 self.write("$")?; 1007 } 1008 DisplayMath(text) => { 1009 self.write("$$")?; 1010 escape_html(&mut self.writer, &text)?; 1011 self.write("$$")?; 1012 } 1013 } 1014 } 1015 Ok(()) 1016 } ``` -------------------------------- ### Handle TagEnd events Source: https://docs.rs/unidown/latest/src/unidown/lib.rs.html Matches TagEnd variants to perform appropriate cleanup or formatting, such as closing tags or updating state variables. ```rust 905 TagEnd::Paragraph => { 906 self.write("\n\n")?; 907 } 908 TagEnd::Heading(_level) => { 909 self.strong = false; 910 self.write("\n\n")?; 911 } 912 TagEnd::Table 913 | TagEnd::BlockQuote(_) 914 | TagEnd::List(_) 915 | TagEnd::Item 916 | TagEnd::FootnoteDefinition => { 917 self.write("\n")?; 918 } 919 TagEnd::TableHead => { 920 self.table_state = TableState::Body; 921 write!( 922 &mut self.writer, 923 "|\n|{}|\n", 924 self.table_alignments 925 .iter() 926 .map(|x| TableAlign::from(*x).as_str().to_owned()) 927 .collect::>() 928 .join("|") 929 )?; 930 } 931 TagEnd::TableRow => { 932 self.write("|\n")?; 933 } 934 TagEnd::TableCell => { 935 self.write(" ")?; 936 self.table_cell_index += 1; 937 } 938 TagEnd::CodeBlock => { 939 self.code = false; 940 self.write("\n")?; 941 } 942 TagEnd::Emphasis => { 943 self.emphasis = false; 944 } 945 TagEnd::Strong => { 946 self.strong = false; 947 } 948 TagEnd::Strikethrough => { 949 self.strike = false; 950 } 951 TagEnd::Link => { 952 let link = self.link.take().unwrap(); 953 escape_href(&mut self.writer, &link.dest_url)?; 954 if !link.title.is_empty() { 955 self.write(" \"")?; 956 escape_html(&mut self.writer, &link.title)?; 957 } 958 self.write("\"]")?; 959 } 960 TagEnd::Image => (), // shouldn't happen, handled in start 961 TagEnd::MetadataBlock(_) => { 962 self.in_non_writing_block = false; 963 } 964 TagEnd::HtmlBlock 965 | TagEnd::DefinitionList 966 | TagEnd::DefinitionListTitle 967 | TagEnd::DefinitionListDefinition 968 | TagEnd::Subscript 969 | TagEnd::Superscript => {} 970 } 971 Ok(()) 972 } ```