diff options
-rw-r--r-- | src/compiler.rs | 12 | ||||
-rw-r--r-- | tests/link_reference.rs | 17 |
2 files changed, 17 insertions, 12 deletions
diff --git a/src/compiler.rs b/src/compiler.rs index 7a11870..fbc4792 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -1047,15 +1047,15 @@ fn on_exit_media(context: &mut CompileContext) { .map(|id| normalize_identifier(&id)); let label = media.label.unwrap(); let definition = id.and_then(|id| context.definitions.get(&id)); - let destination = if let Some(definition) = definition { - &definition.destination - } else { + let destination = if media.destination.is_some() { &media.destination - }; - let title = if let Some(definition) = definition { - &definition.title } else { + &definition.unwrap().destination + }; + let title = if media.destination.is_some() { &media.title + } else { + &definition.unwrap().title }; let destination = if let Some(destination) = destination { diff --git a/tests/link_reference.rs b/tests/link_reference.rs index cac1b39..0904995 100644 --- a/tests/link_reference.rs +++ b/tests/link_reference.rs @@ -256,12 +256,17 @@ fn link_reference() { "should prefer collapsed references over shortcut references" ); - // To do: some bug! - // assert_eq!( - // micromark("[foo]: /url1\n\n[foo]()"), - // "<p><a href=\"\">foo</a></p>", - // "should prefer resources over shortcut references" - // ); + assert_eq!( + micromark("[foo]: /url\n\n[foo]()"), + "<p><a href=\"\">foo</a></p>", + "should prefer resources over shortcut references (1)" + ); + + assert_eq!( + micromark("[foo]: /url \"title\"\n\n[foo]()"), + "<p><a href=\"\">foo</a></p>", + "should prefer resources over shortcut references (2)" + ); assert_eq!( micromark("[foo]: /url1\n\n[foo](not a link)"), |