Skip to content

Commit fdc8bac

Browse files
committed
fix(parsers, markdown, table): Allow empty columns
Empty columns must have a `|` after it and have at least 1 space. Closes #473
1 parent 02824a9 commit fdc8bac

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

lua/markview/parsers/markdown.lua

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,18 +695,22 @@ local function lpeg_processor(line)
695695

696696
local cont = vim.lpeg.C(
697697
( esc_pipe + not_pipe )^1
698-
)
698+
);
699+
local empty_cont = vim.lpeg.C(
700+
( esc_pipe + not_pipe )^1
701+
);
699702

700703
local init_col = pipe * cont * pipe;
701704
local end_col = cont * pipe^-1;
705+
local empty_col = empty_cont * pipe;
702706

703-
local ROW = vim.lpeg.Ct( init_col * end_col^0 );
707+
local ROW = vim.lpeg.Ct( init_col * (empty_col + end_col)^0 );
704708

705709
local RESULT = ROW:match(line);
706710
local _o = {};
707711
local y = 0;
708712

709-
for _, col in ipairs(RESULT or {}) do
713+
for c, col in ipairs(RESULT or {}) do
710714
---|fS
711715

712716
if col == "|" then
@@ -715,6 +719,20 @@ local function lpeg_processor(line)
715719

716720
text = col,
717721

722+
col_start = y,
723+
col_end = y + #col,
724+
});
725+
elseif string.match(col, "%s+") and RESULT[c + 1] == "|" then
726+
--[[
727+
NOTE: An empty column must be followed by a pipe(`|`).
728+
729+
See: #473 for the first case.
730+
]]
731+
table.insert(_o, {
732+
class = "column",
733+
734+
text = col,
735+
718736
col_start = y,
719737
col_end = y + #col,
720738
});

0 commit comments

Comments
 (0)