+ extern fn hoedown_link(
+ ob: *mut hoedown_buffer,
+ content: *const hoedown_buffer,
+ link: *const hoedown_buffer,
+ title: *const hoedown_buffer,
+ data: *const hoedown_renderer_data,
+ _line: libc::size_t
+ ) -> libc::c_int {
+ if link.is_null() {
+ return 0;
+ }
+
+ let opaque = unsafe { (*data).opaque as *mut hoedown_html_renderer_state };
+ let opaque = unsafe { &mut *((*opaque).opaque as *mut MyOpaque) };
+
+ let link = {
+ let s = unsafe { (*link).as_bytes() };
+ str::from_utf8(s).unwrap().to_owned()
+ };
+
+ let link = if let Some(&(_, ref new_target)) = opaque.links_replace
+ .iter()
+ .find(|t| &*t.0 == &*link) {
+ new_target.to_owned()
+ } else {
+ return 0;
+ };
+
+ let content = unsafe {
+ content.as_ref().map(|c| {
+ let s = c.as_bytes();
+ str::from_utf8(s).unwrap().to_owned()
+ })
+ };
+
+ let title = unsafe {
+ title.as_ref().map(|t| {
+ let s = t.as_bytes();
+ str::from_utf8(s).unwrap().to_owned()
+ })
+ };
+
+ let link_out = format!("<a href=\"{link}\"{title}>{content}</a>",
+ link = link,
+ title = title.map_or(String::new(),
+ |t| format!(" title=\"{}\"", t)),
+ content = content.unwrap_or(String::new()));
+
+ unsafe { hoedown_buffer_put(ob, link_out.as_ptr(), link_out.len()); }
+
+ //return "anything but 0" to show we've written the link in
+ 1
+ }