pub struct Comment<'i> { /* private fields */ }
Expand description
An HTML comment rewritable unit.
Exposes API for examination and modification of a parsed HTML comment.
Implementations§
Source§impl<'i> Comment<'i>
impl<'i> Comment<'i>
Sourcepub fn set_text(&mut self, text: &str) -> Result<(), CommentTextError>
pub fn set_text(&mut self, text: &str) -> Result<(), CommentTextError>
Sets the text of the comment.
Sourcepub fn before(&mut self, content: &str, content_type: ContentType)
pub fn before(&mut self, content: &str, content_type: ContentType)
Inserts content
before the comment.
Consequent calls to the method append content
to the previously inserted content.
§Example
use lol_html::{rewrite_str, comments, RewriteStrSettings};
use lol_html::html_content::ContentType;
let html = rewrite_str(
r#"<div><!-- foo --></div>"#,
RewriteStrSettings {
element_content_handlers: vec![
comments!("div", |c| {
c.before("<!-- 42 -->", ContentType::Html);
c.before("bar", ContentType::Text);
Ok(())
})
],
..RewriteStrSettings::new()
}
).unwrap();
assert_eq!(html, r#"<div><!-- 42 -->bar<!-- foo --></div>"#);
Sourcepub fn streaming_before(
&mut self,
string_writer: Box<dyn StreamingHandler + Send + 'static>,
)
pub fn streaming_before( &mut self, string_writer: Box<dyn StreamingHandler + Send + 'static>, )
Inserts content from a StreamingHandler
before the comment.
Consequent calls to the method append to the previously inserted content.
Use the streaming!
macro to make a StreamingHandler
from a closure.
Sourcepub fn after(&mut self, content: &str, content_type: ContentType)
pub fn after(&mut self, content: &str, content_type: ContentType)
Inserts content
after the comment.
Consequent calls to the method prepend content
to the previously inserted content.
§Example
use lol_html::{rewrite_str, comments, RewriteStrSettings};
use lol_html::html_content::ContentType;
let html = rewrite_str(
r#"<div><!-- foo --></div>"#,
RewriteStrSettings {
element_content_handlers: vec![
comments!("div", |c| {
c.after("Bar", ContentType::Text);
c.after("Qux", ContentType::Text);
Ok(())
})
],
..RewriteStrSettings::new()
}
).unwrap();
assert_eq!(html, r#"<div><!-- foo -->QuxBar</div>"#);
Sourcepub fn streaming_after(
&mut self,
string_writer: Box<dyn StreamingHandler + Send + 'static>,
)
pub fn streaming_after( &mut self, string_writer: Box<dyn StreamingHandler + Send + 'static>, )
Inserts content from a StreamingHandler
after the comment.
Consequent calls to the method prepend to the previously inserted content.
Use the streaming!
macro to make a StreamingHandler
from a closure.
Sourcepub fn replace(&mut self, content: &str, content_type: ContentType)
pub fn replace(&mut self, content: &str, content_type: ContentType)
Replaces the comment with the content
.
Consequent calls to the method overwrite previous replacement content.
§Example
use lol_html::{rewrite_str, comments, RewriteStrSettings};
use lol_html::html_content::ContentType;
let html = rewrite_str(
r#"<div><!-- foo --></div>"#,
RewriteStrSettings {
element_content_handlers: vec![
comments!("div", |c| {
c.replace("Bar", ContentType::Text);
c.replace("Qux", ContentType::Text);
Ok(())
})
],
..RewriteStrSettings::new()
}
).unwrap();
assert_eq!(html, r#"<div>Qux</div>"#);
Sourcepub fn streaming_replace(
&mut self,
string_writer: Box<dyn StreamingHandler + Send + 'static>,
)
pub fn streaming_replace( &mut self, string_writer: Box<dyn StreamingHandler + Send + 'static>, )
Replaces the comment with the content from a StreamingHandler
.
Consequent calls to the method overwrite previous replacement content.
Use the streaming!
macro to make a StreamingHandler
from a closure.
Sourcepub fn source_location(&self) -> SourceLocation
pub fn source_location(&self) -> SourceLocation
Position of this comment in the source document, before any rewriting