Skip to content

Commit

Permalink
fix parenthesis in target of labeled link
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon-Laux committed May 7, 2024
1 parent 957f08f commit 63628d8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion message_parser_wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn parse_text(s: &str, enable_markdown: bool) -> JsValue {
serde_wasm_bindgen::to_value(&ast).expect("Element converts to JsValue")
}

/// parses text to json AST (text elements and labled links, to replicate current desktop implementation)
/// parses text to json AST (text elements and labeled links, to replicate current desktop implementation)
#[wasm_bindgen]
pub fn parse_desktop_set(s: &str) -> JsValue {
serde_wasm_bindgen::to_value(&deltachat_message_parser::parser::parse_desktop_set(s))
Expand Down
15 changes: 4 additions & 11 deletions src/parser/parse_from_text/markdown_elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,10 @@ pub(crate) fn labeled_link(input: &str) -> IResult<&str, Element, CustomError<&s
}
let label = parse_all(raw_label);

let (input, raw_link): (&str, &str) = delimited(tag("("), is_not(")"), tag(")"))(input)?;
if raw_link.is_empty() {
return Err(nom::Err::Error(CustomError::NoContent));
}
// check if result is valid link
let (remainder, destination) = LinkDestination::parse_labelled(raw_link)?;
if remainder.is_empty() {
Ok((input, Element::LabeledLink { label, destination }))
} else {
Err(nom::Err::Error(CustomError::InvalidLink))
}
let (input, (_, destination, _)) =
tuple((tag("("), LinkDestination::parse_labelled, tag(")")))(input)?;

Ok((input, Element::LabeledLink { label, destination }))
}

pub(crate) fn parse_element(
Expand Down
11 changes: 11 additions & 0 deletions tests/text_to_ast/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,17 @@ fn labeled_link() {
);
}

#[test]
fn labeled_link_parenthesis_in_target() {
assert_eq!(
parse_markdown_text("[a link](https://delta.chat/en/help(help)hi)"),
vec![LabeledLink {
label: vec![Text("a link")],
destination: https_link_no_puny("https://delta.chat/en/help(help)hi", "delta.chat"),
}]
);
}

#[test]
fn labeled_link_example() {
assert_eq!(
Expand Down

0 comments on commit 63628d8

Please sign in to comment.