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:<n>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 <noreply@anthropic.com>
This commit is contained in:
@@ -46,6 +46,10 @@ pub struct HtmlRenderer {
|
||||
/// names fall through to the default `class="color-<name>"`
|
||||
/// rendering. Matches vimwiki's `color_dic`.
|
||||
colors: HashMap<String, String>,
|
||||
/// 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:<n>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:<n>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-<name>"`.
|
||||
@@ -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"</li>\n")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user