X-Git-Url: https://git.r.bdr.sh/rbdr/page/blobdiff_plain/8d4fac527ea33456de21933b4632a5bf4abbfc8d..0e3bcda2ce1ba4bff5d457e48a82db6e6289aad6:/src/gemini_parser.rs diff --git a/src/gemini_parser.rs b/src/gemini_parser.rs index 36abb16..d0715f1 100644 --- a/src/gemini_parser.rs +++ b/src/gemini_parser.rs @@ -7,7 +7,14 @@ pub fn parse(source: &str) -> String { let mut current_line_type: Option = None; for line in lines { - let line_type = identify_line(&(line[..3]), is_preformatted); + let mut line_type = LineType::Text; + if line.char_indices().count() > 2 { + let mut end = line.len(); + if line.char_indices().count() > 3 { + end = line.char_indices().map(|(i, _)| i).nth(3).unwrap(); + } + line_type = identify_line(&line[..end], is_preformatted); + } match line_type { LineType::PreformattedToggle => is_preformatted = !is_preformatted, _ => { @@ -68,7 +75,14 @@ fn get_full_line_content(line_type: &LineType, line: &str) -> String { match line_type { LineType::Text => format!("

{}

\n", line.trim()), LineType::Blank => "
\n".to_string(), - LineType::Link => format!("
{}
\n", get_link_address(line), get_link_content(line)), + LineType::Link => { + let url = get_link_address(line); + if url.starts_with("gemini:") { + format!("
{}
\n", url, get_link_content(line)) + } else { + format!("
{}
\n", url.replace(".gmi", ".html"), get_link_content(line)) + } + }, LineType::Heading1 => format!("

{}

\n", line[1..].trim()), LineType::Heading2 => format!("

{}

\n", line[2..].trim()), LineType::Heading3 => format!("

{}

\n", line[3..].trim()),