Skip to content

Include line numbers in unclosed HTML tag warnings - #3226

Open
mmustafasenoglu wants to merge 1 commit into
rust-lang:mainfrom
mmustafasenoglu:fix/unclosed-tag-line-numbers
Open

mmustafasenoglu wants to merge 1 commit into
rust-lang:mainfrom
mmustafasenoglu:fix/unclosed-tag-line-numbers

Conversation

@mmustafasenoglu

Copy link
Copy Markdown
Contributor

Fixes #3079

The warning only named the file, so finding the tag meant searching. Event offsets are now tracked through the tree builder and recorded on raw elements, and both warnings (while exiting, end of document) report the opening line plus the exit line.

Changes:

  • crates/mdbook-html/src/html/tree.rs: offset events, source_line on Element, line numbers in both warnings
  • crates/mdbook-html/src/html/mod.rs: offset iterator into the builder
  • tests/testsuite/rendering.rs: updated snapshots, new line-numbers test

Track pulldown-cmark event offsets through the tree builder and record
the opening line on raw HTML elements, so the warnings point at the
source line instead of just the file.

Fixes rust-lang#3079
@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Sep 16, 2026
Comment on lines +28 to +29
.iter()
.filter(|&&b| b == b'\n')

@GuillaumeGomez GuillaumeGomez Sep 22, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.split(b'\n') would be a simpler approach.

View changes since the review

let exit_line = line_number_at_offset(self.source, self.current_offset);
warn!(
"unclosed HTML tag `<{}>` found in `{}` while exiting {tag:?}\n\
"unclosed HTML tag `<{}>`{} found in `{}` while exiting {tag:?} at line {exit_line}\n\

@GuillaumeGomez GuillaumeGomez Sep 22, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"unclosed HTML tag `<{}>`{} found in `{}` while exiting {tag:?} at line {exit_line}\n\
"unclosed HTML tag `<{}>`{open_line} found in `{}` while exiting {tag:?} at line {exit_line}\n\

View changes since the review

let exit_line = line_number_at_offset(self.source, self.source.len());
warn!(
"unclosed HTML tag `<{}>` found in `{}`",
"unclosed HTML tag `<{}>`{} found in `{}` at end of document (line {exit_line})",

@GuillaumeGomez GuillaumeGomez Sep 22, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"unclosed HTML tag `<{}>`{} found in `{}` at end of document (line {exit_line})",
"unclosed HTML tag `<{}>`{open_line} found in `{}` at end of document (line {exit_line})",

View changes since the review

@GuillaumeGomez GuillaumeGomez left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small nits but looks nice overall!

View changes since this review

@rustbot rustbot added S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. and removed S-waiting-on-review Status: waiting on a review labels Sep 22, 2026
@rustbot

rustbot commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unclosed HTML tag warning should mention line numbers

3 participants