pub fn generate_table_of_contents(html: &str) -> Result<String>
Expand description
Generates a table of contents from HTML content.
This function extracts all headers (h1-h6) from the provided HTML content and generates a table of contents as an HTML unordered list.
§Arguments
html
- A string slice that holds the HTML content to process.
§Returns
Result<String>
- The generated table of contents as an HTML string, or an error.
§Examples
use html_generator::utils::generate_table_of_contents;
let html = "<h1>Title</h1><p>Some content</p><h2>Subtitle</h2><p>More content</p><h3>Sub-subtitle</h3>";
let result = generate_table_of_contents(html).unwrap();
assert_eq!(result, r#"<ul><li class="toc-h1"><a href="\#title">Title</a></li><li class="toc-h2"><a href="\#subtitle">Subtitle</a></li><li class="toc-h3"><a href="\#sub-subtitle">Sub-subtitle</a></li></ul>"#);