Skip to content

Commit d324ac3

Browse files
committed
handle multi-line tags in rustdoc::invalid_html_tags
1 parent c25909c commit d324ac3

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/librustdoc/passes/lint/html_tags.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
//! Detects invalid HTML (like an unclosed `<span>`) in doc comments.
22
3+
use std::borrow::Cow;
34
use std::iter::Peekable;
45
use std::ops::Range;
56
use std::str::CharIndices;
67

8+
use itertools::Itertools as _;
79
use pulldown_cmark::{BrokenLink, Event, LinkType, Parser, Tag, TagEnd};
810
use rustc_hir::HirId;
911
use rustc_resolve::rustdoc::source_span_for_markdown_range;
@@ -126,7 +128,18 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item, hir_id: HirId, dox: &
126128
};
127129

128130
let p = Parser::new_with_broken_link_callback(dox, main_body_opts(), Some(&mut replacer))
129-
.into_offset_iter();
131+
.into_offset_iter()
132+
.coalesce(|a, b| {
133+
// for some reason, pulldown-cmark splits html blocks into seperate events for each line.
134+
// we undo this, in order to handle multi-line tags.
135+
match (a, b) {
136+
((Event::Html(_), ra), (Event::Html(_), rb)) if ra.end == rb.start => {
137+
let merged = ra.start..rb.end;
138+
Ok((Event::Html(Cow::Borrowed(&dox[merged.clone()]).into()), merged))
139+
}
140+
x => Err(x),
141+
}
142+
});
130143

131144
for (event, range) in p {
132145
match event {

0 commit comments

Comments
 (0)