Skip to content

Commit

Permalink
feat(renderer_markdown): Dynamic indent_size & shift_width suppor…
Browse files Browse the repository at this point in the history
…t for list items

Ref: #283
  • Loading branch information
OXY2DEV committed Feb 8, 2025
1 parent 25d987a commit 07a6688
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
4 changes: 2 additions & 2 deletions doc/markdown_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -888,8 +888,8 @@ Configuration for various list items.
---
---@field enable boolean
---
---@field indent_size integer Indentation size for list items.
---@field shift_width integer Virtual indentation size for previewed list items.
---@field indent_size integer | fun(buffer: integer, item: __markdown.list_items): integer Indentation size for list items.
---@field shift_width integer | fun(buffer: integer, item: __markdown.list_items): integer Virtual indentation size for previewed list items.
---
---@field marker_dot list_items.ordered Configuration for `n.` list items.
---@field marker_minus list_items.unordered Configuration for `-` list items.
Expand Down
26 changes: 26 additions & 0 deletions lua/definitions/markdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,32 @@ M.__markdown_hr = {
---
---@field enable boolean
---
---@field indent_size integer | fun(buffer: integer, item: __markdown.list_items): integer Indentation size for list items.
---@field shift_width integer | fun(buffer: integer, item: __markdown.list_items): integer Virtual indentation size for previewed list items.
---
---@field marker_dot list_items.ordered Configuration for `n.` list items.
---@field marker_minus list_items.unordered Configuration for `-` list items.
---@field marker_parenthesis list_items.ordered Configuration for `n)` list items.
---@field marker_plus list_items.unordered Configuration for `+` list items.
---@field marker_star list_items.unordered Configuration for `*` list items.
---
---@field wrap? boolean Enables wrap support.
M.markdown_list_items = {
enable = true,
marker_plus = {},
marker_star = {},
marker_minus = {},
marker_dot = {},
marker_parenthesis = {}
};

-- [ Markdown | List items • Static ] -----------------------------------------------------

--- Configuration for list items.
---@class markdown.list_items_static
---
---@field enable boolean
---
---@field indent_size integer Indentation size for list items.
---@field shift_width integer Virtual indentation size for previewed list items.
---
Expand Down
13 changes: 0 additions & 13 deletions lua/markview/parsers/markdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -366,22 +366,9 @@ markdown.list_item = function (buffer, TSNode, _, range)
---_
end

local node = TSNode;
local block = false;

while node do
if node:type() == "block_quote" then
block = true;
break;
end

node = node:parent();
end

---@type __markdown.list_items
markdown.insert({
class = "markdown_list_item",
__block = block,

candidates = candidates,
marker = marker:gsub("%s", ""),
Expand Down
7 changes: 5 additions & 2 deletions lua/markview/renderers/markdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1883,8 +1883,11 @@ end
markdown.list_item = function (buffer, item)
---+${func, Renders List items}

---@type markdown.list_items?
local main_config = spec.get({ "markdown", "list_items" }, { fallback = nil });
---@type markdown.list_items_static?
local main_config = spec.get({ "markdown", "list_items" }, {
fallback = nil,
eval_args = { buffer, item }
});
local range = item.range;

if not main_config then
Expand Down
2 changes: 1 addition & 1 deletion markview.nvim.wiki

0 comments on commit 07a6688

Please sign in to comment.