Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions lychee-lib/src/extract/html/html5ever.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,4 +583,40 @@ mod tests {
let uris = extract_html(input, false);
assert!(uris.is_empty());
}

#[test]
fn test_extract_links_after_empty_verbatim_block() {
// Test that links are correctly extracted after empty <pre><code> blocks
let input = r#"
<body>
<div>
See <a href="https://example.com/1">First</a>
</div>
<pre>
<code></code>
</pre>
<div>
See <a href="https://example.com/2">Second</a>
</div>
</body>
"#;

let expected = vec![
RawUri {
text: "https://example.com/1".to_string(),
element: Some("a".to_string()),
attribute: Some("href".to_string()),
span: span_line(4),
},
RawUri {
text: "https://example.com/2".to_string(),
element: Some("a".to_string()),
attribute: Some("href".to_string()),
span: span_line(10),
},
];

let uris = extract_html(input, false);
assert_eq!(uris, expected);
}
}
43 changes: 40 additions & 3 deletions lychee-lib/src/extract/html/html5gum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,15 @@ impl<S: SpanProvider> Callback<(), usize> for &mut LinkExtractor<S> {
self.verbatim_stack.pop();
}
}
CallbackEvent::EndTag { .. } => {
CallbackEvent::EndTag { name } => {
let tag_name = String::from_utf8_lossy(name);
// Update the current verbatim element name.
//
// Keeps track of the last verbatim element name, so that we can
// properly handle nested verbatim blocks.
if self.filter_verbatim_here()
if !self.include_verbatim
&& let Some(last_verbatim) = self.verbatim_stack.last()
&& last_verbatim == &self.current_element
&& last_verbatim == tag_name.as_ref()
{
self.verbatim_stack.pop();
}
Expand Down Expand Up @@ -726,4 +727,40 @@ mod tests {
let actual = extract_html_fragments(input);
assert_eq!(actual, expected);
}

#[test]
fn test_extract_links_after_empty_verbatim_block() {
// Test that links are correctly extracted after empty <pre><code> blocks
let input = r#"
<body>
<div>
See <a href="https://example.com/1">First</a>
</div>
<pre>
<code></code>
</pre>
<div>
See <a href="https://example.com/2">Second</a>
</div>
</body>
"#;

let expected = vec![
RawUri {
text: "https://example.com/1".to_string(),
element: Some("a".to_string()),
attribute: Some("href".to_string()),
span: span(4, 30),
},
RawUri {
text: "https://example.com/2".to_string(),
element: Some("a".to_string()),
attribute: Some("href".to_string()),
span: span(10, 30),
},
];

let uris = extract_html(input, false);
assert_eq!(uris, expected);
}
}
Loading