feat(client): conceal colour spans down to their coloured text
CI / cargo fmt --check (push) Successful in 25s
CI / cargo clippy (push) Successful in 37s
CI / cargo test (push) Successful in 37s
CI / editor keymaps (push) Successful in 1m48s

A :VimwikiColorize'd word showed the literal
`<span style="color:NAME">TEXT</span>` markup. Now the tags are concealed
and TEXT is painted in NAME, so the buffer shows just the coloured word —
matching the HTML export.

New autoload/nuwiki/colors.vim: nuwiki#colors#refresh() scans the buffer
and, per distinct colour, defines a syntax region that conceals the
`<span …>` / `</span>` tags (concealends) and highlights the body with the
span's actual colour (guifg always; ctermfg for named colours). Idempotent
(clears the group before redefining) and tracked in b:nuwiki_color_seen.

Refresh is driven from three places so it's both correct and immediate:
- syntax/vimwiki.vim: initial pass + re-establish after :colorscheme reload
  (resets the per-buffer cache since :syntax clear drops the regions);
- ftplugin TextChanged/InsertLeave autocmd for spans that arrive via paste/
  undo/external edits;
- colorize() itself calls refresh() right after wrapping, so a freshly
  colorized word conceals instantly (TextChanged doesn't fire reliably mid
  command / in headless ex-mode).

The LSP @vimwikiColor token no longer links to Constant, so in Neovim it
doesn't override the real per-span colour on the concealed text. Pure syntax
+ :highlight — works identically in Vim, coc.nvim, and Neovim, no LSP needed.

Tests: colorize.conceal_hides_tags_shows_text (both harnesses) and
colorize.command_conceals_immediately (vim). Sample wiki's colorize section
notes the conceal. nvim 269, vim 259+18, config-parity green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-31 16:01:21 +00:00
parent 2facb40265
commit 15ba774a28
9 changed files with 146 additions and 2 deletions
+30
View File
@@ -515,6 +515,36 @@ call s:record(
\ 'colorize.ranged_command_no_error',
\ 'err=' . s:cz_err . ' got ' . string(getline(1)))
" Colour spans are concealed down to their text. Put the span on a non-cursor
" line so concealcursor (=c) doesn't reveal it, then refresh + inspect.
call s:set_buf(['plain line', '<span style="color:red">word</span> tail'])
call cursor(1, 1)
call nuwiki#colors#refresh()
let s:cz_l = getline(2)
let s:cz_open = synconcealed(2, 1)[0]
let s:cz_word = synconcealed(2, stridx(s:cz_l, 'word') + 1)
let s:cz_close = synconcealed(2, stridx(s:cz_l, '</span>') + 1)[0]
call s:record(
\ s:cz_open == 1 && s:cz_close == 1 && s:cz_word[0] == 0
\ && synIDattr(synID(2, stridx(s:cz_l, 'word') + 1, 1), 'name') ==# 'nuwikiColorSpan_red' ? 1 : 0,
\ 'colorize.conceal_hides_tags_shows_text',
\ 'open=' . s:cz_open . ' close=' . s:cz_close . ' word=' . s:cz_word[0]
\ . ' grp=' . synIDattr(synID(2, stridx(s:cz_l, 'word') + 1, 1), 'name'))
" Running the command conceals the new span immediately (colorize refreshes;
" no manual step). Move the cursor off the line so concealcursor reveals nothing.
call s:set_buf(['target word', 'other line'])
call cursor(1, 1)
silent VimwikiColorize teal
call cursor(2, 1)
let s:cz_l2 = getline(1)
call s:record(
\ synconcealed(1, 1)[0] == 1
\ && synIDattr(synID(1, stridx(s:cz_l2, 'target') + 1, 1), 'name') ==# 'nuwikiColorSpan_teal' ? 1 : 0,
\ 'colorize.command_conceals_immediately',
\ 'concealed=' . synconcealed(1, 1)[0]
\ . ' grp=' . synIDattr(synID(1, stridx(s:cz_l2, 'target') + 1, 1), 'name'))
" ===== Follow-link resolves + opens in the current window (regression) =====
" follow_link_or_create() must resolve the definition itself and `:edit` the
" target in the CURRENT window — including a page that does not exist yet