fix(html): match vimwiki export output for headings, code fences, tags, anchors (#6)
Exported HTML diverged from upstream vimwiki's :VimwikiAll2HTML in ways that break custom templates' CSS/JS and deep-links. Bring the renderer to parity on the structural differences reported in #6: 1. Headings — restore vimwiki's structure: a wrapping `<div id="{hierarchical}">` (parent anchors joined by `-`), `class="header"`, and an in-heading `<a href="#{hierarchical}">` self-link. The flat `id` stays on the heading element so intra-page TOC / `#anchor` links keep resolving. Ancestor path is tracked while walking top-level headings. 2. Code fences — emit vimwiki's `<pre {raw-attrs}>` (the verbatim text after `{{{`, e.g. `<pre python>`) instead of `<pre><code class="language-X">`, so highlighters wired for vimwiki output apply. The fence text is now preserved verbatim through the lexer/AST (PreformattedNode.attrs). 3. Inline tag ids — drop the `tag-` prefix (`id="wiki"`, not `id="tag-wiki"`). Also fixes a real inconsistency: the LSP validated `[[Page#wiki]]` as resolvable while the HTML emitted `id="tag-wiki"`, so the exported link was broken. 4. Same-page anchors — `[[#Section]]` resolves to `index.html#Section` (current page filename + fragment), matching vimwiki, rather than a bare `#Section`. Also ship vimwiki's stock style.css verbatim as the default stylesheet (was a ~7-line minimal one) so exports look identical out of the box and the `.header`/`.tag`/`.toc`/`done*` classes are styled. Centered headings and the `<div class="toc">` Contents wrapper keep their existing form. Tests updated across core + lsp to the new output; added coverage for hierarchical ids, raw fence attrs, bare tag ids, and the same-page anchor filename. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -81,6 +81,9 @@ pub enum VimwikiTokenKind {
|
||||
PreformattedOpen {
|
||||
language: Option<String>,
|
||||
attrs: HashMap<String, String>,
|
||||
/// Verbatim text after `{{{` (trailing whitespace trimmed), preserved
|
||||
/// so the HTML renderer can reproduce vimwiki's raw `<pre …>` attrs.
|
||||
raw: String,
|
||||
},
|
||||
PreformattedClose,
|
||||
PreformattedLine(String),
|
||||
@@ -421,7 +424,14 @@ impl<'src> LexState<'src> {
|
||||
// pairs separated by spaces. Keep parsing forgiving.
|
||||
let after = trimmed[3..].trim();
|
||||
let (language, attrs) = parse_fence_attrs(after);
|
||||
let kind = VimwikiTokenKind::PreformattedOpen { language, attrs };
|
||||
// vimwiki keeps everything after `{{{` (minus trailing whitespace) and
|
||||
// drops it verbatim into the `<pre>` tag, so capture it unparsed.
|
||||
let raw = trimmed[3..].trim_end().to_string();
|
||||
let kind = VimwikiTokenKind::PreformattedOpen {
|
||||
language,
|
||||
attrs,
|
||||
raw,
|
||||
};
|
||||
let span = Span::new(self.pos_in_line(indent), self.line_end_pos(line));
|
||||
self.push(kind, span);
|
||||
self.mode = BlockMode::Preformatted;
|
||||
|
||||
Reference in New Issue
Block a user