From 0741c349dbe2bbe3ea8641491ca05de691f04727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Fr=C3=B3es=20Franco?= Date: Sat, 30 May 2026 23:11:56 -0300 Subject: [PATCH] feat(core): support configurable list_margin in HTML list rendering Add `HtmlRenderer::with_list_margin`. When the margin is >= 0 the outermost list gets an inline `margin-left:em`; nested lists and the default of -1 stay unstyled (deferring to the stylesheet). Wires the per-wiki vimwiki `list_margin` key into the export pipeline. Co-Authored-By: Claude Opus 4.7 --- crates/nuwiki-core/src/render/html.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/crates/nuwiki-core/src/render/html.rs b/crates/nuwiki-core/src/render/html.rs index 1d3e792..695eeec 100644 --- a/crates/nuwiki-core/src/render/html.rs +++ b/crates/nuwiki-core/src/render/html.rs @@ -46,6 +46,10 @@ pub struct HtmlRenderer { /// names fall through to the default `class="color-"` /// rendering. Matches vimwiki's `color_dic`. colors: HashMap, + /// vimwiki `list_margin`: left margin (in `em`) applied to the + /// outermost list. `-1` (the default) emits no inline style and + /// defers to the stylesheet; `>= 0` forces `margin-left:em`. + list_margin: i32, } impl Default for HtmlRenderer { @@ -61,6 +65,7 @@ impl HtmlRenderer { template: None, vars: HashMap::new(), colors: HashMap::new(), + list_margin: -1, } } @@ -95,6 +100,13 @@ impl HtmlRenderer { self } + /// Set the vimwiki `list_margin`. `-1` defers to the stylesheet; + /// `>= 0` forces a `margin-left:em` on the outermost list. + pub fn with_list_margin(mut self, margin: i32) -> Self { + self.list_margin = margin; + self + } + /// Supply a `color_dic`: vimwiki colour-tag names mapped to their /// CSS values. A name listed here is rendered as `style="color:V"`; /// missing names fall through to `class="color-"`. @@ -236,8 +248,16 @@ impl HtmlRenderer { } fn render_list(&self, n: &ListNode, w: &mut dyn Write) -> io::Result<()> { + self.render_list_nested(n, w, true) + } + + fn render_list_nested(&self, n: &ListNode, w: &mut dyn Write, top: bool) -> io::Result<()> { let tag = if n.ordered { "ol" } else { "ul" }; - writeln!(w, "<{tag}>")?; + if top && self.list_margin >= 0 { + writeln!(w, "<{tag} style=\"margin-left:{}em\">", self.list_margin)?; + } else { + writeln!(w, "<{tag}>")?; + } for item in &n.items { self.render_list_item(item, w)?; } @@ -267,7 +287,7 @@ impl HtmlRenderer { self.render_inlines(&n.children, w)?; if let Some(sublist) = &n.sublist { w.write_all(b"\n")?; - self.render_list(sublist, w)?; + self.render_list_nested(sublist, w, false)?; } w.write_all(b"\n") }