Skip to content

Commit

Permalink
fix(renderer)!:Added experimental support for lists inside block elem…
Browse files Browse the repository at this point in the history
…ents

Normal lists can now exist inside of block quotes. Also supports
nesting.

Note: This is an early iteration so expect bugs.

Closes #115
  • Loading branch information
OXY2DEV committed Aug 20, 2024
1 parent 3adfe75 commit 81c64a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
20 changes: 18 additions & 2 deletions lua/markview/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ parser.fiter_lines = function (buffer, from, to)
local indexes = {};
local spaces = {};
local align_spaces = {};
local start_pos = {};

local withinCodeBlock, insideDescription;
local parent_marker;
Expand All @@ -19,7 +20,21 @@ parser.fiter_lines = function (buffer, from, to)
local code_block_indent = 0;
local desc_indent = 0;

local start = 0;

for l, line in ipairs(captured_lines) do
-- TODO: Find better conditions
if l == 1 and line:match(">%s-([+%-*])") then
local before = line:match("(.*>%s-)[+%-*]");
start = vim.fn.strchars(before);

line = line:gsub(before, "");
table.insert(start_pos, start)
else
line = line:sub(start, #line);
table.insert(start_pos, start);
end

if l ~= 1 then
if withinCodeBlock ~= true and line:match("^%s*([+%-*])") then
break;
Expand Down Expand Up @@ -83,7 +98,7 @@ parser.fiter_lines = function (buffer, from, to)
end
end

return filtered_lines, indexes, spaces, align_spaces;
return filtered_lines, indexes, spaces, align_spaces, start_pos;
end

parser.get_list_end_range = function (buffer, from, to, marker)
Expand Down Expand Up @@ -427,7 +442,7 @@ parser.md = function (buffer, TStree, from, to)
local marker_text = vim.treesitter.get_node_text(marker, buffer);
local symbol = marker_text:gsub("%s", "");

local list_lines, lines, spaces, align_spaces = parser.fiter_lines(buffer, row_start, row_end);
local list_lines, lines, spaces, align_spaces, starts = parser.fiter_lines(buffer, row_start, row_end);
local spaces_before_marker = list_lines[1]:match("^(%s*)" .. symbol .. "%s*");

local c_end, _ = parser.get_list_end_range(buffer, row_start, row_end, symbol)
Expand All @@ -440,6 +455,7 @@ parser.md = function (buffer, TStree, from, to)
list_candidates = lines,
list_lines = list_lines,

starts = starts,
spaces = spaces,
align_spaces = align_spaces,
conceal_spaces = vim.fn.strchars(spaces_before_marker),
Expand Down
4 changes: 2 additions & 2 deletions lua/markview/renderer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,7 @@ renderer.render_lists = function (buffer, content, config_table)

local level = math.floor(before / (config_table.indent_size or 2)) + 1;

vim.api.nvim_buf_set_extmark(buffer, renderer.namespace, line_num, 0, {
vim.api.nvim_buf_set_extmark(buffer, renderer.namespace, line_num, content.starts[l] or 0, {
virt_text_pos = "inline",
virt_text = {
{ string.rep(" ", level * shift) },
Expand All @@ -1535,7 +1535,7 @@ renderer.render_lists = function (buffer, content, config_table)

local level = math.floor(before / (config_table.indent_size or 2)) + 1;

vim.api.nvim_buf_set_extmark(buffer, renderer.namespace, line_num, 0, {
vim.api.nvim_buf_set_extmark(buffer, renderer.namespace, line_num, content.starts[l] or 0, {
virt_text_pos = "inline",
virt_text = {
{ string.rep(" ", level * shift) },
Expand Down

0 comments on commit 81c64a8

Please sign in to comment.