Struct rstml_component::HtmlFormatter
source · pub struct HtmlFormatter<'a> { /* private fields */ }
Expand description
A formatter for serializing HTML nodes and content.
The HtmlFormatter
struct provides a versatile way to serialize HTML nodes and content,
ensuring proper spacing, indentation, and formatting. It’s designed to handle various
types of HTML content and produce well-structured and readable HTML output.
NOTE: Currently, no indentation/readibility is supported. The plan is to implement that later.
Implementations§
source§impl<'a> HtmlFormatter<'a>
impl<'a> HtmlFormatter<'a>
sourcepub fn write_bytes(&mut self, raw: &[u8])
pub fn write_bytes(&mut self, raw: &[u8])
Writes raw bytes to the formatter’s buffer without escaping.
This method appends the specified raw bytes to the formatter’s buffer without performing any additional escaping or modification. It provides a low-level, raw API for directly writing content to the buffer, which can be useful for situations where the content is already properly formatted and safe to include as-is.
§Arguments
raw
: A reference to the raw byte slice that will be written to the buffer.
sourcepub fn write(&mut self, value: &[u8])
pub fn write(&mut self, value: &[u8])
Writes escaped bytes to the formatter’s buffer, ensuring valid HTML characters.
This method accepts a reference to a byte slice containing the content to be written to
the formatter’s buffer. The provided value
is escaped to ensure that it only contains
valid HTML characters, preventing any unintentional issues with the produced HTML content.
§Arguments
value
: A reference to the raw byte slice containing the content to be escaped and written.
sourcepub fn write_doctype(&mut self, value: &[u8])
pub fn write_doctype(&mut self, value: &[u8])
This method appends a DOCTYPE declaration to the formatter’s buffer. The provided value
is
escaped to ensure that it only contains valid characters for a DOCTYPE declaration. The resulting
DOCTYPE declaration is properly formatted and follows the standard syntax of “”.
§Arguments
value
: A reference to the raw byte slice containing the content for the DOCTYPE declaration.
sourcepub fn write_open_tag_start(&mut self, tag: &[u8])
pub fn write_open_tag_start(&mut self, tag: &[u8])
Writes the start of an opening HTML tag to the formatter’s buffer.
This method appends the start of an opening HTML tag to the formatter’s buffer. The provided tag
is used as the tag name, and the tag is not closed. is commonly followed by either write_attribute_name,
write_self_close_tag, or write_open_tag_end.
§Arguments
tag
: A reference to the raw byte slice containing the tag name for the opening tag.
sourcepub fn write_attribute_name(&mut self, name: &[u8])
pub fn write_attribute_name(&mut self, name: &[u8])
Writes an HTML attribute name to the formatter’s buffer.
This method appends an HTML attribute name to the formatter’s buffer. The provided name
is
used as the attribute name.
§Arguments
name
: A reference to the raw byte slice containing the attribute name.
sourcepub fn write_attribute_value(
&mut self,
value: impl HtmlAttributeValue,
) -> Result
pub fn write_attribute_value( &mut self, value: impl HtmlAttributeValue, ) -> Result
Writes an HTML attribute value to the formatter’s buffer.
This method appends an HTML attribute value to the formatter’s buffer. The provided value
is
an instance of a type implementing the HtmlAttributeValue trait. The value is written to the
buffer, ensuring proper formatting and escaping if required.
§Arguments
value
: An instance implementing the HtmlAttributeValue trait, representing the attribute value.
§Returns
A std::fmt::Result indicating the success or failure of the writing operation.
pub fn write_attributes(&mut self, values: impl HtmlAttributes) -> Result
sourcepub fn write_self_close_tag(&mut self)
pub fn write_self_close_tag(&mut self)
Writes a self-closing indicator to the formatter’s buffer.
This method appends a self-closing indicator “ />“ to the formatter’s buffer. It’s commonly used after writing an opening tag to indicate that the tag is self-closing and has no associated content.
sourcepub fn write_open_tag_end(&mut self)
pub fn write_open_tag_end(&mut self)
Writes the end of an opening HTML tag to the formatter’s buffer.
This method appends the end of an opening HTML tag “>” to the formatter’s buffer. It’s commonly used after writing the tag name and its attributes to indicate the completion of the tag’s opening.
sourcepub fn write_end_tag(&mut self, tag: &[u8])
pub fn write_end_tag(&mut self, tag: &[u8])
Writes an HTML end tag to the formatter’s buffer.
This method appends an HTML end tag “</tag>” to the formatter’s buffer. The provided tag
is used
as the tag name for the end tag.
§Arguments
tag
: A reference to the raw byte slice containing the tag name for the end tag.
sourcepub fn write_content(&mut self, content: impl HtmlContent) -> Result
pub fn write_content(&mut self, content: impl HtmlContent) -> Result
Writes HTML content to the formatter’s buffer.
This method appends HTML content to the formatter’s buffer. The provided content
is an
instance of a type implementing the HtmlContent trait. The content is formatted and written
to the buffer according to the implementation of the HtmlContent trait.
§Arguments
content
: An instance implementing the HtmlContent trait, representing the HTML content to write.
§Returns
A std::fmt::Result indicating the success or failure of the writing operation.
sourcepub fn write_comment(&mut self, comment: &[u8])
pub fn write_comment(&mut self, comment: &[u8])
Writes an HTML comment to the formatter’s buffer.
This method appends an HTML comment to the formatter’s buffer. The provided comment
is escaped
to ensure that it only contains valid characters for an HTML comment.
§Arguments
comment
: A reference to the raw byte slice containing the content for the HTML comment.
sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves space in the buffer for writing additional bytes without reallocation.
This method ensures that enough space is reserved in the formatter’s buffer to accommodate
the writing of additional
bytes without needing to reallocate memory. It’s useful to call
this method before writing a significant amount of content, as it can help prevent frequent
reallocations and improve performance.
§Arguments
additional
: The number of additional bytes to reserve space for in the buffer.