aboutsummaryrefslogtreecommitdiff
path: root/htmlua-parser/src/render.rs
diff options
context:
space:
mode:
authorGrace Yoder <70408179+gyoder@users.noreply.github.com>2025-07-12 19:43:55 -0600
committerGitHub <noreply@github.com>2025-07-12 19:43:55 -0600
commitd9efc151c051577b7de843ac249c360917d36736 (patch)
tree644b2f3c2fb8f09d499b7d3f3a0c55eb5e9541f2 /htmlua-parser/src/render.rs
parentc8ffbb2af0eae39b897ff3b1b6c8263181fdd8d4 (diff)
parent38be7b73656d70e21118e1a8b7b6b21c8c20a849 (diff)
Merge pull request #15 from gyoder/config
Basic toml config support.
Diffstat (limited to 'htmlua-parser/src/render.rs')
-rw-r--r--htmlua-parser/src/render.rs28
1 files changed, 18 insertions, 10 deletions
diff --git a/htmlua-parser/src/render.rs b/htmlua-parser/src/render.rs
index 6444d60..9360f16 100644
--- a/htmlua-parser/src/render.rs
+++ b/htmlua-parser/src/render.rs
@@ -1,4 +1,4 @@
-use std::{cell::RefCell, fmt::Write, fs::read_to_string, path::PathBuf, rc::Rc};
+use std::{cell::RefCell, fmt::Write, path::PathBuf, rc::Rc};
use anyhow::{Result, anyhow};
use kuchikiki::{NodeRef, traits::TendrilSink};
@@ -12,7 +12,7 @@ use syntect::{
util::LinesWithEndings,
};
-use crate::helpers::read_doc_from_file;
+use crate::{helpers::read_doc_from_file, serve::get_config};
fn create_htmlua_stdlib(l: &Lua, stdout: &Rc<RefCell<String>>) -> mlua::Result<Table> {
let t = l.create_table()?;
@@ -108,7 +108,11 @@ pub fn expand_template(document: NodeRef, component_path: &PathBuf, include_from
let exported = from_node
.select_first(format!("exportelement.{name}").as_str())
.map_err(|()| anyhow!("Error finding exportelement"))?;
- exported.as_node().children().rev().for_each(|c| i.as_node().insert_after(c));
+ exported
+ .as_node()
+ .children()
+ .rev()
+ .for_each(|c| i.as_node().insert_after(c));
}
}
while let Ok(i) = document.select_first("includeelement") {
@@ -130,8 +134,13 @@ pub fn expand_template(document: NodeRef, component_path: &PathBuf, include_from
item_path.push(include_path);
let new_node = read_doc_from_file(item_path)?;
let replaced_node = expand_template(new_node, component_path, Some(i.as_node()))?;
- replaced_node.select_first("html").map_err(|()| anyhow!("Error finding html"))?.as_node().children().rev().for_each(|c| i.as_node().insert_after(c));
-
+ replaced_node
+ .select_first("html")
+ .map_err(|()| anyhow!("Error finding html"))?
+ .as_node()
+ .children()
+ .rev()
+ .for_each(|c| i.as_node().insert_after(c));
}
}
while let Ok(i) = document.select_first("include") {
@@ -141,16 +150,15 @@ pub fn expand_template(document: NodeRef, component_path: &PathBuf, include_from
}
pub fn process_syntax_highlighting(document: NodeRef) -> Result<NodeRef> {
+ let config = get_config();
let ps = SyntaxSet::load_defaults_newlines();
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");
- let _ = ts.add_from_folder(themes);
+ if !syntax_elements.is_empty() && config.syntax_highlighting.load_custom_themes {
+ let _ = ts.add_from_folder(&config.paths.themes);
}
for node in syntax_elements {
let attrs = match node.as_node().as_element() {
@@ -158,7 +166,7 @@ pub fn process_syntax_highlighting(document: NodeRef) -> Result<NodeRef> {
None => continue,
};
let language = attrs.get("lang").unwrap_or("text");
- let theme_name = attrs.get("theme").unwrap_or("base16-ocean.dark");
+ let theme_name = attrs.get("theme").unwrap_or(&config.syntax_highlighting.default_theme);
if let Some(text_node) = node.as_node().first_child() {
if let Some(code_text) = text_node.as_text() {
let syntax = ps