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().expect("writer output is valid UTF-8");
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_url_encoded_with_policy(
&mut self,
url: &[u8],
policy: RenderPolicy,
)
pub fn write_url_encoded_with_policy( &mut self, url: &[u8], policy: RenderPolicy, )
Write an autolink URL after applying the selected trust policy.
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 write_link_url_with_policy(&mut self, url: &[u8], policy: RenderPolicy)
pub fn write_link_url_with_policy(&mut self, url: &[u8], policy: RenderPolicy)
Write a link destination after applying the selected trust policy.
Sourcepub fn write_link_url_with_policy_and_base(
&mut self,
url: &[u8],
policy: RenderPolicy,
base: Option<&str>,
)
pub fn write_link_url_with_policy_and_base( &mut self, url: &[u8], policy: RenderPolicy, base: Option<&str>, )
Write a link destination with the trust policy, prefixing internal
absolute paths (/… but not //… and not already prefixed) with
base. base must be normalized: non-empty, no trailing slash.
Sourcepub fn as_str(&self) -> Result<&str, Utf8Error>
pub fn as_str(&self) -> Result<&str, Utf8Error>
Get output as a string slice, validating its UTF-8 encoding.
Sourcepub fn into_string(self) -> Result<String, FromUtf8Error>
pub fn into_string(self) -> Result<String, FromUtf8Error>
Take ownership as a string, validating its UTF-8 encoding.
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 colgroup_start(&mut self)
pub fn colgroup_start(&mut self)
Write a table column group start.
Sourcepub fn colgroup_end(&mut self)
pub fn colgroup_end(&mut self)
Write a table column group end.
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, colspan: u16)
pub fn th_start(&mut self, align: Alignment, colspan: u16)
Write a table-header cell start with optional alignment and colspan.
Sourcepub fn td_start(&mut self, align: Alignment, colspan: u16)
pub fn td_start(&mut self, align: Alignment, colspan: u16)
Write a table-data cell start with optional alignment and colspan.
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.