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")
}