(
mut o: impl Write + 'b,
state: &'b mut ParseState,
)
| 412 | } |
| 413 | |
| 414 | fn url<'a, 'b>( |
| 415 | mut o: impl Write + 'b, |
| 416 | state: &'b mut ParseState, |
| 417 | ) -> impl FnMut(&mut Partial<&'a str>) -> PResult<(), Error<'a>> + 'b { |
| 418 | move |i| { |
| 419 | // Save the current input position |
| 420 | let start = i.checkpoint(); |
| 421 | |
| 422 | // Try to match the first part of URL pattern "[text]" |
| 423 | let display = match delimited::<_, _, _, _, Error<'a>, _, _, _>("[", take_until(1.., "]("), "]").parse_next(i) { |
| 424 | Ok(display) => display, |
| 425 | Err(_) => { |
| 426 | // If it doesn't match, reset position and fail |
| 427 | i.reset(&start); |
| 428 | return Err(ErrMode::from_error_kind(i, ErrorKind::Fail)); |
| 429 | }, |
| 430 | }; |
| 431 | |
| 432 | // Try to match the second part of URL pattern "(url)" |
| 433 | let link = match delimited::<_, _, _, _, Error<'a>, _, _, _>("(", take_till(0.., ')'), ")").parse_next(i) { |
| 434 | Ok(link) => link, |
| 435 | Err(_) => { |
| 436 | // If it doesn't match, reset position and fail |
| 437 | i.reset(&start); |
| 438 | return Err(ErrMode::from_error_kind(i, ErrorKind::Fail)); |
| 439 | }, |
| 440 | }; |
| 441 | |
| 442 | // Only generate output if the complete URL pattern matches |
| 443 | queue_newline_or_advance(&mut o, state, display.width() + 1)?; |
| 444 | queue(&mut o, StyledText::info_fg())?; |
| 445 | queue(&mut o, style::Print(format!("{display} ")))?; |
| 446 | queue(&mut o, StyledText::secondary_fg())?; |
| 447 | state.column += link.width(); |
| 448 | queue(&mut o, style::Print(link))?; |
| 449 | queue(&mut o, StyledText::reset()) |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | fn less_than<'a, 'b>( |
| 454 | mut o: impl Write + 'b, |
nothing calls this directly
no test coverage detected