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
24
src/lib.rs
24
src/lib.rs
|
|
@ -84,7 +84,7 @@ pub use self::{element::*, render::*};
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{html::*, Attr, Element, Render};
|
||||
use crate::{html::*, Attr, Content, Element, Render};
|
||||
|
||||
#[test]
|
||||
fn simple_website() {
|
||||
|
|
@ -189,4 +189,26 @@ mod tests {
|
|||
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<()> {
|
||||
write!(w, "<!--")?;
|
||||
|
||||
// A comment...
|
||||
// - 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, "-->")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue