Skip to content

Commit 5465846

Browse files
committed
fix(renderer, typst, code_block): Added wrap support
Closes #470
1 parent 9e852c2 commit 5465846

6 files changed

Lines changed: 20 additions & 4 deletions

File tree

doc/markview.nvim-typst.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ code_blocks *markview.nvim-typst.code_blocks*
4747
---@field sign? string Sign for the code block.
4848
---@field sign_hl? string Highlight group for the sign.
4949
---@field style
50-
---| "simple" Only highlights the lines inside this block.
50+
---| "simple" Only highlights the lines inside this block. This will be used if a `wrap` is enabled or if `tab` is used in the text.
5151
---| "block" Creates a box around the code block.
5252
---@field text string Text to use as the label.
5353
---@field text_direction

lua/markview/parsers/typst.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,20 @@ typst.code = function (buffer, TSNode, text, range)
5454
range = range
5555
});
5656
else
57+
local uses_tab = false;
58+
59+
for _, line in ipairs(text) do
60+
if string.match(line, "\t") then
61+
uses_tab = true;
62+
break;
63+
end
64+
end
65+
5766
typst.insert({
5867
class = "typst_code_block",
5968

69+
uses_tab = uses_tab,
70+
6071
text = text,
6172
range = range
6273
});

lua/markview/renderers/typst.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ typst.code_block = function (buffer, item)
149149
return;
150150
end
151151

152-
if config.style == "simple" then
152+
local win = utils.buf_getwin(buffer);
153+
154+
if not win or config.style == "simple" or item.uses_tab or ( vim.o.wrap == true or vim.wo[win].wrap == true ) then
153155
vim.api.nvim_buf_set_extmark(buffer, typst.ns, range.row_start, range.col_start, {
154156
undo_restore = false, invalidate = true,
155157

@@ -1579,6 +1581,7 @@ typst.render = function (buffer, content)
15791581
local custom = spec.get({ "renderers" }, { fallback = {} });
15801582

15811583
for _, item in ipairs(content or {}) do
1584+
15821585
local success, err;
15831586

15841587
if custom[item.class] then

lua/markview/types/parsers/typst.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
---
99
---@field text string[]
1010
---@field range markview.parsed.range
11+
---
12+
---@field uses_tab boolean Does the lock contain any `tab`s inside it?
1113

1214
------------------------------------------------------------------------------
1315

lua/markview/types/renderers/typst.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
---@field sign? string Sign for the code block.
3939
---@field sign_hl? string Highlight group for the sign.
4040
---@field style
41-
---| "simple" Only highlights the lines inside this block.
41+
---| "simple" Only highlights the lines inside this block. This will be used if a `wrap` is enabled or if `tab` is used in the text.
4242
---| "block" Creates a box around the code block.
4343
---@field text string Text to use as the label.
4444
---@field text_direction

markview.nvim.wiki

0 commit comments

Comments
 (0)