Skip to content

Commit

Permalink
fix: language code block style has been renamed to block
Browse files Browse the repository at this point in the history
  • Loading branch information
OXY2DEV committed Oct 4, 2024
1 parent 1c96867 commit 060a94b
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 91 deletions.
2 changes: 1 addition & 1 deletion lua/definitions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
---
---@field enable boolean
---@field icons string Icon provider
---@field style "simple" | "language" Render style
---@field style "simple" | "block" Render style
---@field hl? string Highlight group for the code block
---@field info_hl? string Highlight group for the info string
---@field language_hl? string Highlight group for the language name
Expand Down
167 changes: 84 additions & 83 deletions lua/markview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,88 @@ markview.state = {
markview.configuration = {
__inside_code_block = false,

buf_ignore = { "nofile" },

callbacks = {
---+ ${class, Callbacks}
on_enable = function (_, window)
local _m = {};

if markview.state.hybrid_mode == true and vim.islist(markview.configuration.hybrid_modes) then
for _, mod in ipairs(markview.configuration.modes) do
if vim.list_contains({ "n", "i", "v", "c" }, mod) and
not vim.list_contains(markview.configuration.hybrid_modes, mod)
then
table.insert(_m, mod);
end
end
else
for _, mod in ipairs(markview.configuration.modes) do
if vim.list_contains({ "n", "i", "v", "c" }, mod) then
table.insert(_m, mod);
end
end
end

vim.wo[window].conceallevel = 2;
vim.wo[window].concealcursor = table.concat(_m);
end,
on_disable = function (_, window)
vim.wo[window].conceallevel = 0;
vim.wo[window].concealcursor = "";
end,

on_mode_change = function (_, window, mode)
if vim.list_contains(markview.configuration.modes, mode) then
local _m = {};

if markview.state.hybrid_mode == true and vim.islist(markview.configuration.hybrid_modes) then
for _, mod in ipairs(markview.configuration.modes) do
if vim.list_contains({ "n", "i", "v", "c" }, mod) and
not vim.list_contains(markview.configuration.hybrid_modes, mod)
then
table.insert(_m, mod);
end
end
else
for _, mod in ipairs(markview.configuration.modes) do
if vim.list_contains({ "n", "i", "v", "c" }, mod) then
table.insert(_m, mod);
end
end
end

vim.wo[window].concealcursor = table.concat(_m);
vim.wo[window].conceallevel = 2;
else
vim.wo[window].conceallevel = 0;
vim.wo[window].concealcursor = "";
end
end,

split_enter = nil
---_
},

debounce = 50,
escaped = { enable = true },

filetypes = { "markdown", "quarto", "rmd" },

highlight_groups = "dynamic",

hybrid_modes = nil,

initial_state = true,
max_file_length = 1000,
modes = { "n", "no", "c" },
render_distance = 100,

split_conf = {
split = "right"
},


block_quotes = {
---+ ${class, Block quote}
enable = true,
Expand Down Expand Up @@ -317,69 +399,6 @@ markview.configuration = {
---_
},

buf_ignore = { "nofile" },

callbacks = {
---+ ${class, Callbacks}
on_enable = function (_, window)
local _m = {};

if markview.state.hybrid_mode == true and vim.islist(markview.configuration.hybrid_modes) then
for _, mod in ipairs(markview.configuration.modes) do
if vim.list_contains({ "n", "i", "v", "c" }, mod) and
not vim.list_contains(markview.configuration.hybrid_modes, mod)
then
table.insert(_m, mod);
end
end
else
for _, mod in ipairs(markview.configuration.modes) do
if vim.list_contains({ "n", "i", "v", "c" }, mod) then
table.insert(_m, mod);
end
end
end

vim.wo[window].conceallevel = 2;
vim.wo[window].concealcursor = table.concat(_m);
end,
on_disable = function (_, window)
vim.wo[window].conceallevel = 0;
vim.wo[window].concealcursor = "";
end,

on_mode_change = function (_, window, mode)
if vim.list_contains(markview.configuration.modes, mode) then
local _m = {};

if markview.state.hybrid_mode == true and vim.islist(markview.configuration.hybrid_modes) then
for _, mod in ipairs(markview.configuration.modes) do
if vim.list_contains({ "n", "i", "v", "c" }, mod) and
not vim.list_contains(markview.configuration.hybrid_modes, mod)
then
table.insert(_m, mod);
end
end
else
for _, mod in ipairs(markview.configuration.modes) do
if vim.list_contains({ "n", "i", "v", "c" }, mod) then
table.insert(_m, mod);
end
end
end

vim.wo[window].concealcursor = table.concat(_m);
vim.wo[window].conceallevel = 2;
else
vim.wo[window].conceallevel = 0;
vim.wo[window].concealcursor = "";
end
end,

split_enter = nil
---_
},

checkboxes = {
---+ ${class, Checkboxes}
enable = true,
Expand Down Expand Up @@ -422,7 +441,7 @@ markview.configuration = {
enable = true,
icons = "internal",

style = "language",
style = "block",
hl = "MarkviewCode",
info_hl = "MarkviewCodeInfo",

Expand All @@ -436,11 +455,6 @@ markview.configuration = {
---_
},

debounce = 50,
escaped = { enable = true },

filetypes = { "markdown", "quarto", "rmd" },

footnotes = {
enable = true,
use_unicode = true,
Expand Down Expand Up @@ -518,15 +532,13 @@ markview.configuration = {
---_
},

highlight_groups = "dynamic",

horizontal_rules = {
---+ ${class, Horizontal rules}
enable = true,

parts = {
{
---+ ${conf, Lsft portion}
---+ ${conf, Left portion}
type = "repeating",
repeat_amount = function () --[[@as function]]
local textoff = vim.fn.getwininfo(vim.api.nvim_get_current_win())[1].textoff;
Expand Down Expand Up @@ -594,8 +606,6 @@ markview.configuration = {
---_
},

hybrid_modes = nil,

injections = {
---+ ${class, Query injections}
enable = true,
Expand Down Expand Up @@ -767,15 +777,6 @@ markview.configuration = {
---_
},

initial_state = true,
max_file_length = 1000,
modes = { "n", "no", "c" },
render_distance = 100,

split_conf = {
split = "right"
},

tables = {
---+ ${class, Tablws}
enable = true,
Expand Down
9 changes: 2 additions & 7 deletions lua/markview/renderer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,7 @@ renderer.render_code_blocks = function (buffer, content, config_table)
-- NOTE: The node actually ends in the next line after the code block
end_row = content.row_end - 1, end_col = content.col_end
});
elseif config_table.style == "minimal" or config_table.style == "language" then
elseif config_table.style == "minimal" or config_table.style == "block" or config_table.style == "language" then
local block_length = content.largest_line;

if type(config_table.min_width) == "number" and config_table.min_width > block_length then
Expand Down Expand Up @@ -1442,18 +1442,13 @@ renderer.render_code_blocks = function (buffer, content, config_table)
-- The text on the final line
-- We need to get the tail section to see if it contains ```
local block_end_line = vim.api.nvim_buf_get_lines(buffer, content.row_end - 1, content.row_end, false)[1];
local tail_section = vim.fn.strcharpart(block_end_line or "", content.col_start);

if tail_section:match("```$") then
tail_section = tail_section:gsub("```$", "");
end

vim.api.nvim_buf_set_extmark(buffer, renderer.namespace, content.row_end - 1, vim.fn.strchars(block_end_line or ""), {
undo_restore = false, invalidate = true,

virt_text_pos = "inline",
virt_text = {
{ string.rep(config_table.pad_char or " ", (block_length - vim.fn.strchars(tail_section)) + ((config_table.pad_amount or 1) * 2)), set_hl(config_table.hl) },
{ string.rep(config_table.pad_char or " ", (block_length) + ((config_table.pad_amount or 1) * 2)), set_hl(config_table.hl) },
},

hl_mode = "combine",
Expand Down

0 comments on commit 060a94b

Please sign in to comment.