diff --git a/src/markdown.rs b/src/markdown.rs index 75b8601..9be64a7 100644 --- a/src/markdown.rs +++ b/src/markdown.rs @@ -253,6 +253,9 @@ pub fn markdown_to_html(content: &str, permalinks: &HashMap, ter }, // Need to handle relative links Event::Start(Tag::Link(ref link, ref title)) => { + if in_header { + return Event::Html(Owned("".to_owned())); + } if link.starts_with("./") { // First we remove the ./ since that's gutenberg specific let clean_link = link.replacen("./", "", 1); @@ -277,6 +280,12 @@ pub fn markdown_to_html(content: &str, permalinks: &HashMap, ter Event::Start(Tag::Link(link.clone(), title.clone())) }, + Event::End(Tag::Link(_, _)) => { + if in_header { + return Event::Html(Owned("".to_owned())); + } + event + } // need to know when we are in a code block to disable shortcodes in them Event::Start(Tag::Code) => { in_code_block = true; @@ -535,6 +544,19 @@ A quote ); } + // See https://github.com/Keats/gutenberg/issues/53 + #[test] + fn test_markdown_to_html_insert_anchor_with_link() { + let mut config = Config::default(); + config.insert_anchor_links = Some(true); + let res = markdown_to_html("## [](#xresources)Xresources", &HashMap::new(), &GUTENBERG_TERA, &config).unwrap(); + assert_eq!( + res, + "

🔗\nXresources

\n" + ); + } + + #[test] fn test_markdown_to_html_insert_anchor_with_other_special_chars() { let mut config = Config::default();