diff options
| author | gyoder <70408179+gyoder@users.noreply.github.com> | 2025-07-07 12:36:28 -0600 |
|---|---|---|
| committer | gyoder <70408179+gyoder@users.noreply.github.com> | 2025-07-07 12:36:28 -0600 |
| commit | 3d50b12df4bd1e81248256893bd9a83498a0dae9 (patch) | |
| tree | e0d3d6ce9c8b12f2508bd3b0b8a518d662b78960 /htmlua-parser | |
| parent | 3f8616e8b08b7eeec94b9019fd3f4ca1216ecb7d (diff) | |
Added custom theme loading
Diffstat (limited to 'htmlua-parser')
| -rw-r--r-- | htmlua-parser/src/render.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/htmlua-parser/src/render.rs b/htmlua-parser/src/render.rs index 396df4f..55047fc 100644 --- a/htmlua-parser/src/render.rs +++ b/htmlua-parser/src/render.rs @@ -139,11 +139,16 @@ pub fn expand_template(document: NodeRef, component_path: &PathBuf, include_from pub fn process_syntax_highlighting(document: NodeRef) -> Result<NodeRef> { let ps = SyntaxSet::load_defaults_newlines(); - let ts = ThemeSet::load_defaults(); + let mut ts = ThemeSet::load_defaults(); let syntax_elements: Vec<_> = match document.select("syntaxhighlight") { Ok(e) => e.collect(), Err(()) => return Err(anyhow!("Unable to find syntaxhighlight elements")), }; + if !syntax_elements.is_empty() { + // TODO: read from config + let themes = PathBuf::from("/var/www/htmlua/themes"); + ts.add_from_folder(themes)?; + } for node in syntax_elements { let attrs = match node.as_node().as_element() { Some(e) => e.attributes.borrow(), @@ -163,8 +168,8 @@ pub fn process_syntax_highlighting(document: NodeRef) -> Result<NodeRef> { write!(html_output, r#"<pre class="syntax-highlight" data-lang="{language}">"#)?; html_output.push_str("<code>"); for line in LinesWithEndings::from(&code_text.borrow()) { - let ranges: Vec<(Style, &str)> = h.highlight_line(line, &ps).unwrap(); - let escaped = styled_line_to_highlighted_html(&ranges[..], IncludeBackground::No).unwrap(); + let ranges: Vec<(Style, &str)> = h.highlight_line(line, &ps)?; + let escaped = styled_line_to_highlighted_html(&ranges[..], IncludeBackground::No)?; html_output.push_str(&escaped); } html_output.push_str("</code></pre>"); |
