Skip to content

Commit

Permalink
fix(parser): Improved validation of pending checkboxes
Browse files Browse the repository at this point in the history
Using [-] anywhere other then the start of a list will no longer be
considered a pending checkbox.

fix: Fixed odd naming of html tags configuration

`config` -> `configs` to make the purpose of the option more obvious.
  • Loading branch information
OXY2DEV committed Aug 5, 2024
1 parent bca5123 commit a6392dd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 31 deletions.
15 changes: 3 additions & 12 deletions lua/definitions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
--- Table for hyperlink configuration
---@field links markview.render_config.links
---
--- Table for hyperlink configuration
--- Table for inline code configuration
---@field inline_codes markview.render_config.inline_codes
---
--- Table for list item configuration
Expand Down Expand Up @@ -137,7 +137,7 @@
--- Used for highlighting the line when the style is "simple"
---@field hl string?
---
--- Character added before the heading name to seperate heading levels
--- Character added before the heading name to separate heading levels
---@field shift_char string?
---
--- Highlight group for shift_char
Expand Down Expand Up @@ -258,10 +258,7 @@
---@class markview.render_config.block_quotes.callouts
---
--- String to match to detect the callout, this is not case-sensitive
---@field match_string string
---
--- Aliases for the callout, this is not case-sensitive
---@field aliases string[]?
---@field match_string string|string[]
---
--- The text to show for the callout
---@field callout_preview string
Expand Down Expand Up @@ -371,12 +368,6 @@
--- Default highlight group for the various parts
---@field hl string?
---
--- Custom text for the heading. The heading text is used when nil
---@field text string?
---
--- Highlight group for the heading text, inherits from icon_hl
---@field text_hl string?
---
--- Used bu the "label" style to add text before the left padding
---@field corner_left string?
---
Expand Down
2 changes: 1 addition & 1 deletion lua/markview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ markview.configuration = {
conceal = false
},

config = {
configs = {
b = { conceal = true, hl = "Bold" },
strong = { conceal = true, hl = "Bold" },

Expand Down
39 changes: 28 additions & 11 deletions lua/markview/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -453,25 +453,42 @@ parser.md_inline = function (buffer, TStree, from, to)
local title = string.match(line ~= nil and line[1] or "", "%b[]%s*(.*)$")

if capture_text == "[-]" then
table.insert(parser.parsed_content, {
node = capture_node,
type = "checkbox",
state = "pending",
for _, extmark in ipairs(parser.parsed_content) do
if extmark.type == "list_item" and extmark.row_start == row_start then
local start_line = extmark.list_lines[1] or "";
local atStart = start_line:match("%-%s+(%[%-%])%s+");

row_start = row_start,
row_end = row_end,
local chk_start, _ = start_line:find("%[%-%]");

col_start = col_start,
col_end = col_end
})
if not atStart or not chk_start or chk_start - 1 ~= col_start then
goto invalid;
end

table.insert(parser.parsed_content, {
node = capture_node,
type = "checkbox",
state = "pending",

row_start = row_start,
row_end = row_end,

col_start = col_start,
col_end = col_end
});

break;
end
::invalid::
end
else
for _, extmark in ipairs(parser.parsed_content) do
if extmark.type == "block_quote" and extmark.row_start == row_start then

extmark.callout = string.match(capture_text, "%[!([^%]]+)%]");
extmark.title = title;

extmark.line_width = vim.fn.strchars(line[1])
extmark.line_width = vim.fn.strchars(line[1]);

break;
end
end
end
Expand Down
14 changes: 7 additions & 7 deletions lua/markview/renderer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ local display_width = function (text, config)
local tag_conf = html_conf.tags;
local conf = tag_conf.default or {};

if tag_conf.config and tag_conf.config[string.lower(filtered_tag)] then
conf = tag_conf.config[string.lower(filtered_tag)]
if tag_conf.configs and tag_conf.configs[string.lower(filtered_tag)] then
conf = tag_conf.configs[string.lower(filtered_tag)]
end

local internal_text = tmp_string:match("<" .. start_tag .. ">(.-)</" .. end_tag .. ">") or "";
Expand Down Expand Up @@ -1068,10 +1068,10 @@ renderer.render_block_quotes = function (buffer, content, config_table)

if content.callout ~= nil then
for _, callout in ipairs(config_table.callouts) do
if type(callout.match_string) == "string" and callout.match_string:upper() == content.callout:upper() then
if type(callout.match_string) == "string" and string.upper(callout.match_string --[[@as string]]) == content.callout:upper() then
qt_config = callout;
elseif vim.islist(callout.aliases) then
for _, alias in ipairs(callout.aliases) do
elseif vim.islist(callout.match_string) then
for _, alias in ipairs(callout.match_string --[[@as string[] ]]) do
if type(alias) == "string" and alias:upper() == content.callout.upper() then
qt_config = callout;
end
Expand Down Expand Up @@ -1424,8 +1424,8 @@ renderer.render_html_inline = function (buffer, content, user_config)

local html_conf = user_config.tags.default or {};

if user_config.tags.config[string.lower(content.tag)] then
html_conf = user_config.tags.config[string.lower(content.tag)];
if user_config.tags.configs[string.lower(content.tag)] then
html_conf = user_config.tags.configs[string.lower(content.tag)];
end

if html_conf.conceal ~= false then
Expand Down

0 comments on commit a6392dd

Please sign in to comment.