pub struct HtmlWriter { /* private fields */ }Expand description
HTML output writer with pre-allocated, reusable buffer.
§Example
use ferromark::HtmlWriter;
let mut writer = HtmlWriter::with_capacity_for(1000);
writer.write_str("<p>");
writer.write_escaped_text(b"Hello <World>");
writer.write_str("</p>");
let html = writer.into_string();
assert_eq!(html, "<p>Hello <World></p>");Implementations§
Source§impl HtmlWriter
impl HtmlWriter
Sourcepub fn with_capacity_for(input_len: usize) -> Self
pub fn with_capacity_for(input_len: usize) -> Self
Create with pre-allocated capacity based on expected input size.
Typical HTML is ~1.25x input size; we reserve extra for safety.
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create with explicit capacity.
Sourcepub fn write_bytes(&mut self, bytes: &[u8])
pub fn write_bytes(&mut self, bytes: &[u8])
Write raw bytes without escaping.
Sourcepub fn write_string(&mut self, s: &str)
pub fn write_string(&mut self, s: &str)
Write a dynamic string without escaping.
Sourcepub fn write_byte(&mut self, b: u8)
pub fn write_byte(&mut self, b: u8)
Write a single byte.
Sourcepub fn write_escaped_text(&mut self, text: &[u8])
pub fn write_escaped_text(&mut self, text: &[u8])
Write text with HTML escaping (for text content).
Sourcepub fn write_text_with_entities(&mut self, text: &[u8])
pub fn write_text_with_entities(&mut self, text: &[u8])
Write text with entity decoding and HTML escaping (for inline text content). First decodes HTML entities, then escapes for output.
Sourcepub fn write_escaped_range(&mut self, input: &[u8], range: Range)
pub fn write_escaped_range(&mut self, input: &[u8], range: Range)
Write text with HTML escaping from a range.
Sourcepub fn write_escaped_attr(&mut self, attr: &[u8])
pub fn write_escaped_attr(&mut self, attr: &[u8])
Write attribute value with full escaping (including quotes).
Sourcepub fn write_escaped_link_attr(&mut self, attr: &[u8])
pub fn write_escaped_link_attr(&mut self, attr: &[u8])
Write URL/title with backslash escape processing and HTML attribute escaping. Backslash-escaped punctuation characters have the backslash removed.
Sourcepub fn write_link_title(&mut self, title: &[u8])
pub fn write_link_title(&mut self, title: &[u8])
Write link title with entity decoding, backslash escape processing, and HTML escaping.
Sourcepub fn write_url_encoded(&mut self, url: &[u8])
pub fn write_url_encoded(&mut self, url: &[u8])
Write autolink URL with percent-encoding and HTML escaping. Used for autolink hrefs per CommonMark spec.
Sourcepub fn write_link_url(&mut self, url: &[u8])
pub fn write_link_url(&mut self, url: &[u8])
Write link destination with backslash escape processing and URL encoding.
Used for link destinations in [text](url) syntax.
Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Take ownership as String.
Sourcepub fn buffer_mut(&mut self) -> &mut Vec<u8> ⓘ
pub fn buffer_mut(&mut self) -> &mut Vec<u8> ⓘ
Get mutable reference to internal buffer.
Use with caution - allows bypassing escaping.
Sourcepub fn self_closing_tag(&mut self, tag: &'static str)
pub fn self_closing_tag(&mut self, tag: &'static str)
Write self-closing tag: <tagname />
Sourcepub fn open_tag_nl(&mut self, tag: &'static str)
pub fn open_tag_nl(&mut self, tag: &'static str)
Write opening tag with newline: <tagname>\n
Sourcepub fn close_tag_nl(&mut self, tag: &'static str)
pub fn close_tag_nl(&mut self, tag: &'static str)
Write closing tag with newline: </tagname>\n
Sourcepub fn paragraph_start(&mut self)
pub fn paragraph_start(&mut self)
Write paragraph start: <p>
Sourcepub fn paragraph_end(&mut self)
pub fn paragraph_end(&mut self)
Write paragraph end: </p>\n
Sourcepub fn heading_start(&mut self, level: u8)
pub fn heading_start(&mut self, level: u8)
Write heading start: <hN>
Sourcepub fn heading_start_with_id(&mut self, level: u8, id: &str)
pub fn heading_start_with_id(&mut self, level: u8, id: &str)
Write heading start with ID: <hN id="slug">
Sourcepub fn heading_end(&mut self, level: u8)
pub fn heading_end(&mut self, level: u8)
Write heading end: </hN>\n
Sourcepub fn code_block_start(&mut self, lang: Option<&[u8]>)
pub fn code_block_start(&mut self, lang: Option<&[u8]>)
Write code block start with optional language class. Processes backslash escapes in the language string.
Sourcepub fn write_info_string_attr(&mut self, info: &[u8])
pub fn write_info_string_attr(&mut self, info: &[u8])
Write fenced code info string with entity decoding and attribute escaping.
Sourcepub fn code_block_end(&mut self)
pub fn code_block_end(&mut self)
Write code block end: </code></pre>\n
Sourcepub fn thematic_break(&mut self)
pub fn thematic_break(&mut self)
Write thematic break: <hr />\n
Sourcepub fn blockquote_start(&mut self)
pub fn blockquote_start(&mut self)
Write blockquote start: <blockquote>\n
Sourcepub fn blockquote_end(&mut self)
pub fn blockquote_end(&mut self)
Write blockquote end: </blockquote>\n
Sourcepub fn callout_start(&mut self, callout: CalloutType)
pub fn callout_start(&mut self, callout: CalloutType)
Write callout/admonition start.
Sourcepub fn callout_end(&mut self)
pub fn callout_end(&mut self)
Write callout/admonition end.
Sourcepub fn ol_start(&mut self, start: Option<u32>)
pub fn ol_start(&mut self, start: Option<u32>)
Write list start (ordered): <ol>\n or <ol start="N">\n
Sourcepub fn table_start(&mut self)
pub fn table_start(&mut self)
Write table start: <table>\n
Sourcepub fn thead_start(&mut self)
pub fn thead_start(&mut self)
Write thead start: <thead>\n
Sourcepub fn tbody_start(&mut self)
pub fn tbody_start(&mut self)
Write tbody start: <tbody>\n
Sourcepub fn th_start(&mut self, align: Alignment)
pub fn th_start(&mut self, align: Alignment)
Write th start with optional alignment: <th> or <th align="...">
Sourcepub fn td_start(&mut self, align: Alignment)
pub fn td_start(&mut self, align: Alignment)
Write td start with optional alignment: <td> or <td align="...">
Sourcepub fn inline_code(&mut self, content: &[u8])
pub fn inline_code(&mut self, content: &[u8])
Write inline code: <code>escaped_content</code>
Sourcepub fn strong_start(&mut self)
pub fn strong_start(&mut self)
Write strong start: <strong>
Sourcepub fn strong_end(&mut self)
pub fn strong_end(&mut self)
Write strong end: </strong>
Sourcepub fn link_start(&mut self, url: &[u8], title: Option<&[u8]>)
pub fn link_start(&mut self, url: &[u8], title: Option<&[u8]>)
Write link start: <a href="url">
Sourcepub fn line_break(&mut self)
pub fn line_break(&mut self)
Write line break: <br />\n
Sourcepub fn write_html_filtered(&mut self, html: &[u8])
pub fn write_html_filtered(&mut self, html: &[u8])
Write raw HTML with GFM disallowed-tag filtering.
Replaces < with < before disallowed tag names.