Fix html comment rendering
Apparently I just completely forgot to actually include <!-- and -->, and instead just rendered the comment contents.
This commit is contained in:
parent
ec7bc571b1
commit
0167d3cea3
3 changed files with 30 additions and 1 deletions
|
|
@ -21,6 +21,10 @@ A dependency update to an incompatible version is considered a breaking change.
|
||||||
|
|
||||||
- `html::attr::Rel`
|
- `html::attr::Rel`
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Rendering of HTML comments
|
||||||
|
|
||||||
## v0.1.2 - 2024-12-14
|
## v0.1.2 - 2024-12-14
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
||||||
24
src/lib.rs
24
src/lib.rs
|
|
@ -84,7 +84,7 @@ pub use self::{element::*, render::*};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{html::*, Attr, Element, Render};
|
use crate::{html::*, Attr, Content, Element, Render};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn simple_website() {
|
fn simple_website() {
|
||||||
|
|
@ -189,4 +189,26 @@ mod tests {
|
||||||
r#"<html lang="EN"></html>"#,
|
r#"<html lang="EN"></html>"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn comments() {
|
||||||
|
assert_eq!(
|
||||||
|
html(("<!--abc--> ", Content::comment("abc")))
|
||||||
|
.render_to_string()
|
||||||
|
.unwrap(),
|
||||||
|
r#"<html><!--abc--> <!--abc--></html>"#,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
html(Content::comment("Hello <!-- world -->!"))
|
||||||
|
.render_to_string()
|
||||||
|
.unwrap(),
|
||||||
|
r#"<html><!--Hello <!== world ==>!--></html>"#,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
html(Content::comment("-><!-")).render_to_string().unwrap(),
|
||||||
|
r#"<html><!-- -><!- --></html>"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -246,6 +246,8 @@ fn render_text<W: fmt::Write>(w: &mut W, text: &str) -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_comment<W: fmt::Write>(w: &mut W, text: &str) -> Result<()> {
|
fn render_comment<W: fmt::Write>(w: &mut W, text: &str) -> Result<()> {
|
||||||
|
write!(w, "<!--")?;
|
||||||
|
|
||||||
// A comment...
|
// A comment...
|
||||||
// - must not start with the string ">"
|
// - must not start with the string ">"
|
||||||
// - must not start with the string "->"
|
// - must not start with the string "->"
|
||||||
|
|
@ -269,6 +271,7 @@ fn render_comment<W: fmt::Write>(w: &mut W, text: &str) -> Result<()> {
|
||||||
write!(w, " ")?;
|
write!(w, " ")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
write!(w, "-->")?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue