1
0
mirror of https://github.com/lise-henry/crowbook synced 2024-09-24 23:40:43 +02:00

Consider an image as standalone even if it is inside a link

This commit is contained in:
Elisabeth Henry 2017-03-20 03:16:05 +01:00
parent b3ba91c424
commit bed329466d
2 changed files with 23 additions and 1 deletions

View File

@ -380,7 +380,21 @@ fn find_standalone(ast: &mut Vec<Token>) {
unreachable!();
}
} else {
continue;
// If paragraph only contains a link only containing an image, ok too
if let Token::Link(ref url, ref alt, ref mut inner) = inner[0] {
if inner[0].is_image() {
if let Token::Image(source, title, inner) = mem::replace(&mut inner[0],
Token::Rule) {
Token::Link(url.clone(), alt.clone(), vec![Token::StandaloneImage(source, title, inner)])
} else {
unreachable!();
}
} else {
continue;
}
} else {
continue;
}
}
} else {
continue;

View File

@ -160,6 +160,14 @@ fn image_standalone() {
test_eq(&result, expected);
}
#[test]
fn image_link_standalone() {
let doc = "[![alt text](http://foo.bar/baz.png \"Title\")](http://foo.bar)";
let expected = r#"[Link("http://foo.bar", "", [StandaloneImage("http://foo.bar/baz.png", "Title", [Str("alt text")])])]"#;
let result = format!("{:?}", parse_from_str(doc));
test_eq(&result, expected);
}
#[test]
fn table_simple() {
let doc = "