馃 The Definitive Gemini Protocol Toolkit
gemini gemini-protocol gemtext parser zero-dependency toolkit ast converter html markdown cli networking
at main 57 lines 1.1 kB view raw
1pub enum HeadingLevel { 2 One, 3 Two, 4 Three, 5} 6 7#[must_use] 8pub fn heading( 9 text: &(impl ToString + ?Sized), 10 level: &HeadingLevel, 11) -> String { 12 format!( 13 "{} {}", 14 match level { 15 HeadingLevel::One => "#", 16 HeadingLevel::Two => "##", 17 HeadingLevel::Three => "###", 18 }, 19 text.to_string() 20 ) 21} 22 23#[must_use] 24pub fn list_item(text: &(impl ToString + ?Sized)) -> String { 25 format!("* {}", text.to_string()) 26} 27 28#[must_use] 29pub fn list_items(items: &[&(impl ToString + ?Sized)]) -> String { 30 items 31 .iter() 32 .map(|item| list_item(&item.to_string())) 33 .collect::<Vec<_>>() 34 .join("\n") 35} 36 37#[must_use] 38pub fn link(text: &(impl ToString + ?Sized), location: Option<&str>) -> String { 39 format!( 40 "=> {}{}", 41 text.to_string(), 42 location.map_or_else(String::new, |l| format!(" {l}")) 43 ) 44} 45 46#[must_use] 47pub fn block_quote(text: &(impl ToString + ?Sized)) -> String { 48 format!("> {}", text.to_string()) 49} 50 51#[must_use] 52pub fn preformatted_text( 53 text: &(impl ToString + ?Sized), 54 alt_text: Option<&str>, 55) -> String { 56 format!("```{}\n{}\n```", alt_text.unwrap_or(""), text.to_string()) 57}