Implement contiguous preformat blocks with alt-text
Dependencies
- [2]
HVFBGX2AImplement basic text/gemini - [3]
DBKKKHC2Initial commit - [4]
ONQEIR5BWIP mime-type handling - [*]
3SPNKI46Improve parsing. Add modules that were missed
Change contents
- edit in src/main.rs at line 63[6.7856][2.41]
println!("response body: {body}"); - replacement in src/main.rs at line 144
url: Url,url: TextLine<'a>, - replacement in src/main.rs at line 148
Preformatted(TextLine<'a>),Preformatted(Preformat<'a>), - edit in src/main.rs at line 151
}#[derive(Clone, Debug)]pub struct Preformat<'a> {alt: TextLine<'a>,lines: Vec<TextLine<'a>>, - replacement in src/main.rs at line 166
fn string_to_line(preformat: bool, string: TextLine<'_>) -> RawLine {fn string_to_preformat(string: TextLine<'_>) -> Option<TextLine<'_>> {let line = string.0;if line.starts_with("```") {// ignore anything after the lead chars on preformat linesreturn None;} else {// ignore any other formatting between preformat toggle linesreturn Some(string);}}fn string_to_line(string: TextLine<'_>) -> RawLine { - replacement in src/main.rs at line 179
match line {if line.starts_with("```") { - replacement in src/main.rs at line 181
"```" => {return RawLine::Toggle {alt: TextLine(&line[3..]),}}// ignore any other formatting between preformat toggle lines_ if preformat => Line::Preformatted(string),"=> " => {let line = &line[3..];match line.split_once(' ') {Some((url, desc)) => {let url = url.trim_start_matches(' ');Line::Link {url: url.parse().expect("invalid link url"),description: Some(TextLine(desc)),}return RawLine::Toggle {alt: TextLine(&line[3..]),};} else if line.starts_with("=> ") {let line = &line[3..];match line.split_once(' ') {Some((url, desc)) => {let url = url.trim_start_matches(' ');Line::Link {url: TextLine(url),description: Some(TextLine(desc)), - edit in src/main.rs at line 193
None => Line::Link {url: line.parse().expect("invalid link url"),description: None,}, - edit in src/main.rs at line 194
None => Line::Link {url: TextLine(line),description: None,}, - replacement in src/main.rs at line 199
"* " => Line::ListItem(TextLine(&line[2..])),"# " => Line::Heading {} else if line.starts_with("* ") {Line::ListItem(TextLine(&line[2..]))} else if line.starts_with("# ") {Line::Heading { - replacement in src/main.rs at line 205
},"## " => Line::Heading {}} else if line.starts_with("## ") {Line::Heading { - replacement in src/main.rs at line 210
},"### " => Line::Heading {}} else if line.starts_with("### ") {Line::Heading { - replacement in src/main.rs at line 215
},"> " => Line::Quote(TextLine(&line[2..])),_ => Line::Text(string),}} else if line.starts_with(">") {Line::Quote(TextLine(&line[1..]))} else {Line::Text(string) - replacement in src/main.rs at line 224
value.lines().map(TextLine)// start with preformatting set to off.scan(false, |preformat, line| {match string_to_line(*preformat, line) {// if we hit a toggle line, switch preformatting modeRawLine::Toggle { alt } => {*preformat = !*preformat;None{let mut outer = vec![];let mut preformat_block: Option<Preformat> = None;let lines = value.lines().map(TextLine);for line in lines {if preformat_block.is_some() {match string_to_preformat(line) {// if we hit a toggle line, switch preformatting modeNone => {let Some(i) = preformat_block.take()else {unreachable!("This is within the is_some arm of the if")};outer.push(Line::Preformatted(i));}Some(p) => preformat_block.as_mut().unwrap().lines.push(p),}} else {match string_to_line(line) {// if we hit a toggle line, switch preformatting modeRawLine::Toggle { alt } => {preformat_block = Some(Preformat { alt, lines: vec![] });}RawLine::Line(l) => outer.push(l), - edit in src/main.rs at line 247
// otherwise, yield the lineRawLine::Line(l) => Some(l), - replacement in src/main.rs at line 248
}).collect()}outer}