Skip to content

Commit

Permalink
fix: Fixes incorrect label highlight group for code blocks(markdown o…
Browse files Browse the repository at this point in the history
…nly)

Closes #230
  • Loading branch information
OXY2DEV committed Dec 29, 2024
1 parent 0ace4ff commit b17370e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 28 deletions.
19 changes: 6 additions & 13 deletions lua/markview/filetypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -730,12 +730,9 @@ fts.get = function (ft)
local provider_name = spec.get({ "preview", "icon_provider" }, { fallback = "internal" });
local conf = {};

if
provider_name == "devicons" and
pcall(require, "nvim-web-devicons")
then
if provider_name == "devicons" and pcall(require, "nvim-web-devicons") then
conf.icon, conf.icon_hl = require("nvim-web-devicons").get_icon(
string.format("example.%s", _ft),
string.format("example.%s", ft),
nil,
{ default = true }
);
Expand All @@ -745,13 +742,10 @@ fts.get = function (ft)
conf.sign = conf.icon;
conf.sign_hl = conf.icon_hl;
conf.border_hl = conf.icon_hl;
elseif
provider_name == "mini" and
pcall(require, "mini.icons")
then
elseif provider_name == "mini" and pcall(require, "mini.icons") then
conf.icon, conf.icon_hl = require("mini.icons").get(
"file",
string.format("example.%s", _ft)
string.format("example.%s", ft)
);

conf.icon = conf.icon .. " ";
Expand All @@ -763,9 +757,8 @@ fts.get = function (ft)
conf = fts.styles[_ft] or fts.styles[ft] or fts.styles["default"];
end

if conf.name == nil then
conf.name = ft or "Unknown";
end
local this_conf = fts.styles[_ft] or fts.styles[ft] or fts.styled.default;
conf.name = this_conf.name or ft or "Unknown";

return conf;
end
Expand Down
64 changes: 49 additions & 15 deletions lua/markview/renderers/markdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1119,13 +1119,7 @@ markdown.code_block = function (buffer, item)
local label = { string.format(" %s%s ", decorations.icon, decorations.name), config.label_hl or decorations.icon_hl };
local win = utils.buf_getwin(buffer);

if
config.style == "simple" or
(
vim.o.wrap == true or
vim.wo[win].wrap == true
)
then
if config.style == "simple" or ( vim.o.wrap == true or vim.wo[win].wrap == true ) then
vim.api.nvim_buf_set_extmark(buffer, markdown.ns, range.row_start, range.col_start, {
end_col = range.col_start + item.text[1]:len(),
conceal = "",
Expand Down Expand Up @@ -1184,9 +1178,13 @@ markdown.code_block = function (buffer, item)

if config.label_direction == nil or config.label_direction == "left" then
vim.api.nvim_buf_set_extmark(buffer, markdown.ns, range.row_start, range.col_start, {
undo_restore = false, invalidate = true,

end_col = range.col_start + (range.info_start or range.lang_end or 0),
conceal = "",
undo_restore = false, invalidate = true,

hl_group = utils.set_hl(config.hl),
hl_mode = "combine"
});
vim.api.nvim_buf_set_extmark(buffer, markdown.ns, range.row_start, range.col_start + (range.lang_end or 0), {
undo_restore = false, invalidate = true,
Expand All @@ -1196,6 +1194,8 @@ markdown.code_block = function (buffer, item)

sign_text = config.sign == true and decorations.sign or nil,
sign_hl_group = utils.set_hl(config.sign_hl or decorations.sign_hl),

hl_mode = "combine"
});

vim.api.nvim_buf_set_extmark(buffer, markdown.ns, range.row_start, range.col_start, {
Expand All @@ -1209,7 +1209,10 @@ markdown.code_block = function (buffer, item)
vim.api.nvim_buf_set_extmark(buffer, markdown.ns, range.row_start, (range.col_start + range.info_start) + pad_amount + (block_width - (preview + 1)), {
end_col = range.col_start + item.text[1]:len(),
conceal = "",
hl_group = utils.set_hl(config.hl),

undo_restore = false, invalidate = true,
hl_mode = "combine"
});
vim.api.nvim_buf_set_extmark(buffer, markdown.ns, range.row_start, range.col_start + item.text[1]:len(), {
undo_restore = false, invalidate = true,
Expand All @@ -1219,6 +1222,8 @@ markdown.code_block = function (buffer, item)
{ "", utils.set_hl(config.hl) },
{ string.rep(config.pad_char or " ", pad_amount), utils.set_hl(config.hl) }
},

hl_mode = "combine"
});
else
vim.api.nvim_buf_set_extmark(buffer, markdown.ns, range.row_start, range.col_start + range.info_end, {
Expand All @@ -1230,23 +1235,31 @@ markdown.code_block = function (buffer, item)
{ string.rep(config.pad_char or " ", pad_amount), utils.set_hl(config.hl) },
{ string.rep(config.pad_char or " ", pad_amount), utils.set_hl(config.hl) }
},

hl_mode = "combine"
});
end
else
vim.api.nvim_buf_set_extmark(buffer, markdown.ns, range.row_start, range.col_start, {
undo_restore = false, invalidate = true,
end_col = range.col_start + item.text[1]:len(),
conceal = "",

hl_mode = "combine"
});

vim.api.nvim_buf_set_extmark(buffer, markdown.ns, range.row_start, range.col_start + item.text[1]:len(), {
undo_restore = false, invalidate = true,
hl_group = utils.set_hl(config.hl),

virt_text_pos = "inline",
virt_text = {
{ string.rep(config.pad_char or " ", block_width - preview), utils.set_hl(config.hl) },
{ string.rep(config.pad_char or " ", pad_amount), utils.set_hl(config.hl) },
{ string.rep(config.pad_char or " ", pad_amount), utils.set_hl(config.hl) },
}
},

hl_mode = "combine"
});
end
elseif config.label_direction == "right" then
Expand All @@ -1262,20 +1275,25 @@ markdown.code_block = function (buffer, item)

sign_text = config.sign == true and sign or nil,
sign_hl_group = utils.set_hl(config.sign_hl or sign_hl or hl),

hl_group = utils.set_hl(config.hl)
});

vim.api.nvim_buf_set_extmark(buffer, markdown.ns, range.row_start, range.col_start, {
end_col = range.col_start + item.text[1]:len(),
hl_group = utils.set_hl(config.info_hl or config.hl),
undo_restore = false, invalidate = true,

end_col = range.col_start + item.text[1]:len(),
hl_group = utils.set_hl(config.info_hl or config.hl)
});

if item.info_string then
if (preview + 1 + vim.fn.strdisplaywidth(item.info_string)) >= (block_width - (2 * pad_amount)) then
vim.api.nvim_buf_set_extmark(buffer, markdown.ns, range.row_start, (range.col_start + range.info_start) + (block_width - (preview + 1)), {
undo_restore = false, invalidate = true,
end_col = range.col_start + item.text[1]:len(),
conceal = "",
hl_group = utils.set_hl(config.hl),

conceal = ""
});

vim.api.nvim_buf_set_extmark(buffer, markdown.ns, range.row_start, range.col_start + range.info_end, {
Expand All @@ -1287,6 +1305,8 @@ markdown.code_block = function (buffer, item)
{ string.rep(config.pad_char or " ", pad_amount), utils.set_hl(config.hl) },
label
},

hl_mode = "combine"
});
else
vim.api.nvim_buf_set_extmark(buffer, markdown.ns, range.row_start, range.col_start + range.info_end, {
Expand All @@ -1297,12 +1317,15 @@ markdown.code_block = function (buffer, item)
{ string.rep(config.pad_char or " ", pad_amount + (block_width - (preview + #item.info_string))), utils.set_hl(config.hl) },
label
},

hl_mode = "combine"
});
end
else
vim.api.nvim_buf_set_extmark(buffer, markdown.ns, range.row_start, range.col_start, {
undo_restore = false, invalidate = true,
end_col = range.col_start + item.text[1]:len(),

conceal = "",
});

Expand All @@ -1313,15 +1336,20 @@ markdown.code_block = function (buffer, item)
{ string.rep(config.pad_char or " ", block_width - preview), utils.set_hl(config.hl) },
{ string.rep(config.pad_char or " ", pad_amount), utils.set_hl(config.hl) },
label
}
},

hl_mode = "combine"
});
end
end

vim.api.nvim_buf_set_extmark(buffer, markdown.ns, range.row_end - 1, range.col_start, {
undo_restore = false, invalidate = true,

end_col = range.col_start + #item.text[#item.text],
conceal = "",
undo_restore = false, invalidate = true

hl_group = utils.set_hl(config.hl)
});
vim.api.nvim_buf_set_extmark(buffer, markdown.ns, range.row_end - 1, range.col_start + #item.text[#item.text], {
undo_restore = false, invalidate = true,
Expand All @@ -1330,7 +1358,9 @@ markdown.code_block = function (buffer, item)
{ string.rep(config.pad_char or " ", pad_amount), utils.set_hl(config.hl) },
{ string.rep(config.pad_char or " ", block_width), utils.set_hl(config.hl) },
{ string.rep(config.pad_char or " ", pad_amount), utils.set_hl(config.hl) }
}
},

hl_mode = "combine"
});

for l = range.row_start + 1, range.row_end - 2, 1 do
Expand Down Expand Up @@ -1358,6 +1388,8 @@ markdown.code_block = function (buffer, item)
{ string.rep(" ", offset),},
{ string.rep(config.pad_char or " ", pad_amount), utils.set_hl(config.hl) }
},

hl_mode = "combine"
});

--- Right padding
Expand All @@ -1369,6 +1401,8 @@ markdown.code_block = function (buffer, item)
{ string.rep(config.pad_char or " ", block_width - vim.fn.strdisplaywidth(final)), utils.set_hl(config.hl) },
{ string.rep(config.pad_char or " ", pad_amount), utils.set_hl(config.hl) }
},

hl_mode = "combine"
});

--- Background color
Expand Down

0 comments on commit b17370e

Please sign in to comment.