fix(export): render vimwiki-compatible HTML for templates, links, and tasks
Stock vimwiki templates and stylesheets rendered broken pages because the
HTML output diverged from vimwiki conventions on three fronts:
- Templates: the renderer only substituted nuwiki's `{{key}}` placeholders,
so vimwiki's `%title%`/`%content%`/`%root_path%`/`%date%`/`%wiki_css%`
passed through literally — dropping the body and breaking asset links.
Both delimiter styles are now recognised; `%wiki_css%` aliases the css var.
- Links: `[[todo.wiki]]` exported to `todo.wiki.html`. render_page_html now
takes the wiki file extension and strips it from wiki/interwiki targets
(via index::strip_wiki_extension) before the `.html` URL is built, matching
in-editor navigation. file:/local: links keep their literal extension.
- Tasks: checkbox items used bespoke `task-*` classes plus an `<input>`,
which double-rendered against vimwiki stylesheets. Emit `done0..done4`
(`[ ] [.] [o] [O] [X]`) and `rejected` (`[-]`) classes with no input — the
stylesheet draws the box.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -242,6 +242,7 @@ fn render_page_html_substitutes_title_content_and_extras() {
|
||||
"Home",
|
||||
DiaryDate::from_ymd(2026, 5, 11).unwrap(),
|
||||
&c.html,
|
||||
None,
|
||||
extras,
|
||||
)
|
||||
.unwrap();
|
||||
@@ -260,6 +261,7 @@ fn render_page_html_uses_metadata_date_when_set() {
|
||||
"Home",
|
||||
DiaryDate::from_ymd(2026, 5, 11).unwrap(),
|
||||
&c.html,
|
||||
None,
|
||||
HashMap::new(),
|
||||
)
|
||||
.unwrap();
|
||||
@@ -276,6 +278,7 @@ fn render_page_html_root_path_for_nested_pages() {
|
||||
"diary/2026-05-11",
|
||||
DiaryDate::today_utc(),
|
||||
&c.html,
|
||||
None,
|
||||
HashMap::new(),
|
||||
)
|
||||
.unwrap();
|
||||
@@ -294,12 +297,64 @@ fn render_page_html_extra_var_overrides_default() {
|
||||
"H",
|
||||
DiaryDate::today_utc(),
|
||||
&c.html,
|
||||
None,
|
||||
extras,
|
||||
)
|
||||
.unwrap();
|
||||
assert!(html.contains("D=OVERRIDE"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_page_html_substitutes_vimwiki_percent_template() {
|
||||
// A stock vimwiki template (%title%/%content%/%root_path%/%wiki_css%/%date%)
|
||||
// must render fully — every placeholder resolved, no literal `%…%` left.
|
||||
let ast = parse("%title My Page\n= One =\nbody text\n");
|
||||
let c = cfg("/tmp/x");
|
||||
let template = "<title>%title%</title>\
|
||||
<link href=\"%root_path%%wiki_css%\">\
|
||||
<body>%content%</body><footer>%date%</footer>";
|
||||
let html = export::render_page_html(
|
||||
&ast,
|
||||
Some(template.into()),
|
||||
"diary/2026-05-11",
|
||||
DiaryDate::from_ymd(2026, 5, 11).unwrap(),
|
||||
&c.html,
|
||||
None,
|
||||
HashMap::new(),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(html.contains("<title>My Page</title>"), "title: {html}");
|
||||
assert!(html.contains("body text"), "content: {html}");
|
||||
assert!(
|
||||
html.contains("href=\"../style.css\""),
|
||||
"root_path+css: {html}"
|
||||
);
|
||||
assert!(html.contains("<footer>2026-05-11</footer>"), "date: {html}");
|
||||
assert!(!html.contains('%'), "placeholder left behind: {html}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_page_html_strips_wiki_extension_from_links() {
|
||||
// A link written with the extension (`[[todo.wiki]]`) must export to
|
||||
// `todo.html`, not `todo.wiki.html` — matching in-editor navigation.
|
||||
let ast = parse("[[todo.wiki|Tasks]] and [[posts/index|Posts]]\n");
|
||||
let c = cfg("/tmp/x");
|
||||
let html = export::render_page_html(
|
||||
&ast,
|
||||
Some("{{content}}".into()),
|
||||
"index",
|
||||
DiaryDate::today_utc(),
|
||||
&c.html,
|
||||
Some(".wiki"),
|
||||
HashMap::new(),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(html.contains("href=\"todo.html\""), "stripped: {html}");
|
||||
assert!(!html.contains("todo.wiki.html"), "not double-ext: {html}");
|
||||
// A link without the extension is unaffected.
|
||||
assert!(html.contains("href=\"posts/index.html\""), "plain: {html}");
|
||||
}
|
||||
|
||||
// ===== fallback_template + DEFAULT_CSS =====
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user