summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/generate_html.rs21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/generate_html.rs b/src/generate_html.rs
index 6887f37..daa83d5 100644
--- a/src/generate_html.rs
+++ b/src/generate_html.rs
@@ -179,9 +179,24 @@ pub fn document_to_html(page: &Page, website: &Website) -> String {
Level::Heading2 => "h2",
Level::Heading3 => "h3",
};
- wrap!(heading_tag, format!("id='{url}'"), {
- tag!("a", line, format!("href='#{url}'"));
- });
+ // Find out whether line contains a link.
+ let mut contains_link = false;
+ for token in &line.tokens {
+ if let Token::InternalLink { .. } | Token::ExternalLink { .. } = token {
+ contains_link = true;
+ break;
+ }
+ }
+ if !contains_link {
+ wrap!(heading_tag, format!("id='{url}'"), {
+ tag!("a", line, format!("href='#{url}'"));
+ });
+ } else {
+ // Leave off the heading <a> tag if the heading already contains
+ // a link (<a> tags cannot be nested).
+ tag!(heading_tag, line, format!("id='{url}'"));
+ }
+
}
Block::Paragraph(line) => tag!("p", line),
Block::Math(content) => html!("<div class='math'>{}</div>", sanitize_text(content, false)),