diff --git a/lua/markview.lua b/lua/markview.lua index 5b8ca24..093a58f 100644 --- a/lua/markview.lua +++ b/lua/markview.lua @@ -703,6 +703,33 @@ markview.configuration = { end end }, + { + group_name = "CodeInfo", + value = function () + local bg = markview.colors.get({ + markview.colors.get_hl_value(0, "Normal", "bg"), + markview.colors.get_hl_value(0, "Cursor", "fg"), + + vim.o.background == "dark" and "#1e1e2e" or "#cdd6f4" + }); + + local luminosity = markview.colors.get_brightness(bg); + + if luminosity < 0.5 then + return { + bg = markview.colors.mix(bg, bg, 1, math.max(luminosity, 0.25)), + fg = markview.colors.get_hl_value(0, "Comment", "fg"), + default = true + }; + else + return { + bg = markview.colors.mix(bg, bg, 1, math.min(luminosity, 0.25) * -1), + fg = markview.colors.get_hl_value(0, "Comment", "fg"), + default = true + }; + end + end + }, { group_name = "InlineCode", value = function () @@ -991,6 +1018,7 @@ markview.configuration = { style = "language", hl = "MarkviewCode", + info_hl = "MarkviewCodeInfo", min_width = 60, pad_amount = 3, diff --git a/lua/markview/parser.lua b/lua/markview/parser.lua index 405f128..92026ec 100644 --- a/lua/markview/parser.lua +++ b/lua/markview/parser.lua @@ -168,7 +168,6 @@ parser.md = function (buffer, TStree, from, to) local heading_txt = capture_node:next_sibling(); local title = heading_txt ~= nil and vim.treesitter.get_node_text(heading_txt, buffer) or nil; - local h_txt_r_start, h_txt_c_start, h_txt_r_end, h_txt_c_end; table.insert(parser.parsed_content, { node = capture_node, @@ -205,10 +204,26 @@ parser.md = function (buffer, TStree, from, to) table.insert(line_lens, len); end + local language_string, additional_info = "", nil; + + -- chore: This needs more work + if block_start:match("^%s*```{{?([^}]*)}}?") then + language_string = block_start:match("^%s*```{{?([^}]*)}}?"); + additional_info = block_start:match("^%s*```{{?[^}]*}}?%s*(.*)$"); + elseif block_start:match("^%s*```(%S*)$") then + language_string = block_start:match("^%s*```(%S*)$"); + elseif block_start:match("%s*```(%S*)%s*") then + language_string = block_start:match("%s*```(%S*)%s"); + additional_info = block_start:match("^%s*```%S*%s+(.*)$"); + end + table.insert(parser.parsed_content, { node = capture_node, type = "code_block", - language = block_start:match("%s*```(%S*)$") or "", + language = language_string, + + info_string = block_start:gsub("^%s*", ""), + block_info = additional_info, line_lengths = line_lens, largest_line = highest_len, diff --git a/lua/markview/renderer.lua b/lua/markview/renderer.lua index 13fa05d..12150e2 100644 --- a/lua/markview/renderer.lua +++ b/lua/markview/renderer.lua @@ -983,6 +983,7 @@ renderer.render_code_blocks = function (buffer, content, config_table) end local lang_width = vim.fn.strchars(" " .. icon .. " " .. languageName .. " "); + local info_width = math.min(vim.fn.strchars(content.info_string or ""), content.largest_line); if config_table.language_direction == nil or config_table.language_direction == "left" then vim.api.nvim_buf_set_extmark(buffer, renderer.namespace, content.row_start, content.col_start + 3 + vim.fn.strlen(content.language), { @@ -999,10 +1000,26 @@ renderer.render_code_blocks = function (buffer, content, config_table) hl_mode = "combine", }); elseif config_table.language_direction == "right" then - vim.api.nvim_buf_set_extmark(buffer, renderer.namespace, content.row_start, content.col_start + 3 + vim.fn.strlen(content.language), { + vim.api.nvim_buf_set_extmark(buffer, renderer.namespace, content.row_start, content.col_start, { + end_col = vim.fn.strchars(content.info_string), + conceal = "", + }); + + local rendered_info = vim.fn.strcharpart(content.block_info or "", 0, block_length - lang_width + ((config_table.pad_amount or 1) * 2) - 4); + + if content.block_info ~= "" and vim.fn.strchars(content.block_info) > (block_length - lang_width - ((content.pad_amount or 1) * 2)) then + rendered_info = rendered_info .. "..."; + -- Hi + end + vim.print(rendered_info) + + -- vim.print(content.col_start + vim.fn.strchars(content.info_string)) + + vim.api.nvim_buf_set_extmark(buffer, renderer.namespace, content.row_start, content.col_start + 3, { virt_text_pos = config_table.position or "inline", virt_text = { - { string.rep(config_table.pad_char or " ", block_length - lang_width + ((config_table.pad_amount or 1) * 2)), set_hl(config_table.hl) }, + { rendered_info, set_hl(config_table.info_hl or config_table.hl) }, + { string.rep(config_table.pad_char or " ", block_length - lang_width - vim.fn.strchars(rendered_info) + ((config_table.pad_amount or 1) * 2)), set_hl(config_table.hl) }, { " " .. icon .. " ", set_hl(hl) }, { languageName .. " ", set_hl(config_table.name_hl) or set_hl(hl) }, },