Skip to content

Commit

Permalink
feat: add "height-from-empty-lines" sizing strategy to markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd committed Jun 24, 2023
1 parent 0aaa660 commit 6412397
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions lua/image/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local default_options = {
integrations = {
markdown = {
enabled = true,
sizing_strategy = "height-from-empty-lines",
},
},
margin = {
Expand Down
33 changes: 31 additions & 2 deletions lua/image/integrations/markdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,41 @@ local render = function(ctx)
local windows = utils.window.get_visible_windows()
ctx.clear()

local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)

for _, window in ipairs(windows) do
if vim.bo[window.buf].filetype == "markdown" then
local images = get_buffer_images(window.buf)

for _, image in ipairs(images) do
local id = utils.random.id()
ctx.render_relative_to_window(window, id, image.url, image.range.start_col, image.range.start_row + 1, 100, 100)
-- local id = utils.random.id()
local id = string.format("%d:%d:%d", window.id, window.buf, image.range.start_row)
utils.log("rendering", id)

local max_width = window.width
local max_height = window.height

if ctx.options.sizing_strategy == "height-from-empty-lines" then
local empty_lines = -1
for i = image.range.end_row + 2, #lines do
if lines[i] == "" then
empty_lines = empty_lines + 1
else
break
end
end
max_height = empty_lines
end

ctx.render_relative_to_window(
window,
id,
image.url,
image.range.start_col,
image.range.start_row + 1,
max_width,
max_height
)
end
end
end
Expand Down
5 changes: 4 additions & 1 deletion work
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@

* Development
[x] core: rearchitect integrations to handle all events internally and only delegate rendering
[ ] markdown: add "height-from-empty-lines" strategy
[x] markdown: add "height-from-empty-lines" strategy
[ ] markdown: handle folding
[ ] ueberzug: throttle/batch calls
[ ] ueberzug: debug multiple images clearing eachother
[ ] core: restructure global state
[ ] log: add debug flag and options (level, file, etc)
[ ] logic: window-image-buffer binding & event handling
Expand Down

0 comments on commit 6412397

Please sign in to comment.