feat(13.1): colorize + color_dic → ColorNode renderer
Closes the last pending §13.1 entries: - **`nuwiki.colorize`** (client-side, Lua + VimL) — wraps the word at cursor (or the visual selection on Neovim) in an inline `<span style="color:%c">…</span>` template. Matches vimwiki's default `color_tag_template`. Bound to `<Leader>wc` in both normal and visual mode on both editor paths; the previous "deferred" stub is gone. - **`color_dic` → renderer** — `HtmlConfig` gains a `color_dic: HashMap<String, String>` field reading the same key out of `initializationOptions` / `didChangeConfiguration`. The HTML export path threads it into `HtmlRenderer::with_colors`; `ColorNode` now picks `style="color:<value>"` when the colour name is in the dict, falling back to the existing `class="color-<name>"` when it isn't. SPEC §13.1 is fully checked off — the table moved from "deferred sketch" to a per-command status table marking all 11 commands done, plus a note on the `color_dic` follow-up landing alongside. README's "Phase 14 list & table edit commands" row now reads ✅ without the deferred-subset caveat, and the §13.1-blocked text-objects note in the keymaps section is rephrased as "planned follow-ups". Tests: 4 new in `phase17_colorize.rs` covering the renderer fallback when the dict is empty, the inline-style emission for a listed name, the fallback path for an unlisted name in a populated dict, and the `initializationOptions` JSON shape. Total 414 Rust tests pass; clippy clean; keymap harness still 20/20. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -36,6 +36,11 @@ pub struct HtmlRenderer {
|
||||
link_resolver: LinkResolver,
|
||||
template: Option<String>,
|
||||
vars: HashMap<String, String>,
|
||||
/// `color_dic`-style override: vimwiki colour-tag names → CSS
|
||||
/// values (`"red"` / `"#ffe119"` / `"oklch(…)"`). Unspecified
|
||||
/// names fall through to the default `class="color-<name>"`
|
||||
/// rendering. Matches SPEC §12.11 `color_dic`.
|
||||
colors: HashMap<String, String>,
|
||||
}
|
||||
|
||||
impl Default for HtmlRenderer {
|
||||
@@ -50,6 +55,7 @@ impl HtmlRenderer {
|
||||
link_resolver: Arc::new(default_link_resolver),
|
||||
template: None,
|
||||
vars: HashMap::new(),
|
||||
colors: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +89,14 @@ impl HtmlRenderer {
|
||||
self.vars = vars;
|
||||
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>"`.
|
||||
pub fn with_colors(mut self, colors: HashMap<String, String>) -> Self {
|
||||
self.colors = colors;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Renderer for HtmlRenderer {
|
||||
@@ -441,9 +455,15 @@ impl HtmlRenderer {
|
||||
}
|
||||
|
||||
fn render_color(&self, n: &ColorNode, w: &mut dyn Write) -> io::Result<()> {
|
||||
write!(w, "<span class=\"color-")?;
|
||||
write_escaped(&n.color, w)?;
|
||||
w.write_all(b"\">")?;
|
||||
if let Some(css) = self.colors.get(&n.color) {
|
||||
w.write_all(b"<span style=\"color:")?;
|
||||
write_escaped(css, w)?;
|
||||
w.write_all(b"\">")?;
|
||||
} else {
|
||||
w.write_all(b"<span class=\"color-")?;
|
||||
write_escaped(&n.color, w)?;
|
||||
w.write_all(b"\">")?;
|
||||
}
|
||||
self.render_inlines(&n.children, w)?;
|
||||
w.write_all(b"</span>")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user