Code
//! The following syntax outputs an error, even though it is a valid SVG!
//! It thinks that `<rect />` is unclosed when it spans multiple lines.
//!
//! <svg width="512" height="512" viewBox="0 0 512" fill="none" xmlns="http://www.w3.org/2000/svg">
//! <rect
//! width="256"
//! height="256"
//! fill="#5064C8"
//! stroke="black"
//! />
//! </svg>
//!
//! However, putting it on a single line works like expected:
//!
//! <svg width="512" height="512" viewBox="0 0 512" fill="none" xmlns="http://www.w3.org/2000/svg">
//! <rect width="256" height="256" fill="#5064C8" stroke="black" />
//! </svg>
//!
//! "Normal" HTML elements like `<img />` do work like normal, even if they span multiple lines,
//! both with and without an outer div.
//!
//! <div>
//! <img
//! src="https://github.com/rust-lang/rust-artwork/blob/master/logo/rust-logo-512x512.png?raw=true"
//! width="512"
//! height="512"
//! />
//! </div>
fn main() {
println!("Hello, world!");
}
Reproduction Steps
- Embed an SVG into rustdoc with a self-closing element like
<rect /> or <path />, formatted to span multiple lines.
- Run
cargo doc.
- See the output.
Expected Outcome
No warnings.
Actual Output
$ cargo doc
Documenting rustdoc_bug v0.1.0 (/home/joona/Programming/rustdoc_bug)
warning: unclosed HTML tag `rect`
--> src/main.rs:4:9
|
4 | //! <rect
| ^^^^^
|
= note: `#[warn(rustdoc::invalid_html_tags)]` on by default
warning: `rustdoc_bug` (bin "rustdoc_bug" doc) generated 1 warning
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.17s
Generated /home/joona/Programming/rustdoc_bug/target/doc/rustdoc_bug/index.html
Version
rustdoc 1.89.0
Additional Details
It's possible that this applies to any non-HTML elements. In my case, I ran into it with SVGs. I store (small) SVGs in my src directory, and use #[doc = include_str!("path/to/image.svg")] to embed them in docs, but I get warnings unless I force self-closing elements to span only one line.
Code
Reproduction Steps
<rect />or<path />, formatted to span multiple lines.cargo doc.Expected Outcome
No warnings.
Actual Output
Version
rustdoc 1.89.0
Additional Details
It's possible that this applies to any non-HTML elements. In my case, I ran into it with SVGs. I store (small) SVGs in my
srcdirectory, and use#[doc = include_str!("path/to/image.svg")]to embed them in docs, but I get warnings unless I force self-closing elements to span only one line.