diff --git a/lua/definitions.lua b/lua/definitions.lua index 6a94091..ff235f2 100644 --- a/lua/definitions.lua +++ b/lua/definitions.lua @@ -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 @@ -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 @@ -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 @@ -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? --- diff --git a/lua/markview.lua b/lua/markview.lua index e9660f9..214eeea 100644 --- a/lua/markview.lua +++ b/lua/markview.lua @@ -1197,7 +1197,7 @@ markview.configuration = { conceal = false }, - config = { + configs = { b = { conceal = true, hl = "Bold" }, strong = { conceal = true, hl = "Bold" }, diff --git a/lua/markview/parser.lua b/lua/markview/parser.lua index 8f255b6..405f128 100644 --- a/lua/markview/parser.lua +++ b/lua/markview/parser.lua @@ -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 diff --git a/lua/markview/renderer.lua b/lua/markview/renderer.lua index af55e3a..8a77231 100644 --- a/lua/markview/renderer.lua +++ b/lua/markview/renderer.lua @@ -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 .. ">(.-)") or ""; @@ -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 @@ -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