From 5375e30bda630b7da358a0a56f592973f249902a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Fr=C3=B3es=20Franco?= Date: Thu, 2 Jul 2026 16:43:02 +0000 Subject: [PATCH] =?UTF-8?q?fix(tables):=20don't=20skip=20escaped=20`\|`=20?= =?UTF-8?q?in=20cell=20scan=20=E2=80=94=20match=20the=20server?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The server lexer (nuwiki-rs) splits table cells on a backslash-escaped `\|` (it can't skip it yet without leaving a stray backslash in the output), but the client's cell_bar_positions was skipping `\|`. That made the editor auto-align keep `a\|b` as one cell while HTML export split it into two. Drop the `\|` case from both clients so buffer alignment and export agree. `[[…]]` / `{{…}}` / `` `code` `` pipes are still treated as literal. A coordinated `\|` follow-up (server unescaping + client re-adding the skip) is tracked in nuwiki-rs. Co-Authored-By: Claude Opus 4.8 --- autoload/nuwiki/commands.vim | 13 +++++++------ lua/nuwiki/commands.lua | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/autoload/nuwiki/commands.vim b/autoload/nuwiki/commands.vim index 2926ab1..d57885e 100644 --- a/autoload/nuwiki/commands.vim +++ b/autoload/nuwiki/commands.vim @@ -1161,9 +1161,12 @@ endfunction " 0-based byte offsets of the cell-separator `|` in `s`. Pipes that are literal " cell content are skipped: those inside `[[…]]` wikilinks, `{{…}}` -" transclusions, `` `…` `` inline code, and backslash-escaped `\|`. Byte-based -" (strpart/stridx) to match the rest of the table code. Keeps a `[[url|title]]` -" link in one cell instead of splitting on its internal pipe. +" transclusions, and `` `…` `` inline code. Byte-based (strpart/stridx) to match +" the rest of the table code. Keeps a `[[url|title]]` link in one cell instead +" of splitting on its internal pipe. +" +" Backslash-escaped `\|` is intentionally NOT skipped, to match the server +" lexer (nuwiki-rs). See the nuwiki-rs issue for the coordinated `\|` follow-up. function! s:cell_bar_positions(s) abort let l:out = [] let l:i = 0 @@ -1171,9 +1174,7 @@ function! s:cell_bar_positions(s) abort while l:i < l:n let l:c = strpart(a:s, l:i, 1) let l:two = strpart(a:s, l:i, 2) - if l:c ==# '\' - let l:i += 2 - elseif l:c ==# '`' + if l:c ==# '`' let l:close = stridx(a:s, '`', l:i + 1) let l:i = l:close < 0 ? l:n : l:close + 1 elseif l:two ==# '[[' diff --git a/lua/nuwiki/commands.lua b/lua/nuwiki/commands.lua index ed67924..76f2649 100644 --- a/lua/nuwiki/commands.lua +++ b/lua/nuwiki/commands.lua @@ -823,18 +823,19 @@ local is_table_row = require('nuwiki.util').is_table_row -- 1-based byte positions of the cell-separator `|` characters in `s`. Pipes -- that are literal cell content are skipped: those inside `[[…]]` wikilinks, --- `{{…}}` transclusions, `` `…` `` inline code, and backslash-escaped `\|`. --- This keeps a `[[url|title]]` link in one cell instead of splitting on its --- internal pipe. +-- `{{…}}` transclusions, and `` `…` `` inline code. This keeps a +-- `[[url|title]]` link in one cell instead of splitting on its internal pipe. +-- +-- Backslash-escaped `\|` is intentionally NOT skipped, to match the server +-- lexer (nuwiki-rs), which can't skip it yet without leaving a stray backslash +-- in the output. See nuwiki-rs issue for the coordinated `\|` follow-up. local function cell_bar_positions(s) local out = {} local i = 1 local n = #s while i <= n do local c = s:sub(i, i) - if c == '\\' then - i = i + 2 -- skip the escaped char (e.g. `\|`) - elseif c == '`' then + if c == '`' then local close = s:find('`', i + 1, true) i = (close or n) + 1 elseif s:sub(i, i + 1) == '[[' then