Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions lua/neorg/modules/core/highlights/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@ module.config.public = {
link = "+NonText",
escape = "+@type",
},

-- Rendered Latex, this will dictate the foreground color of latex images rendered via
-- core.latex.renderer
rendered = {
latex = "+Normal",
}
},

-- Handles the dimming of certain highlight groups.
Expand Down Expand Up @@ -593,22 +599,22 @@ module.public = {
return "NONE"
end,

hex_to_rgb = function(hex_colour)
return tonumber(hex_colour:sub(1, 2), 16),
tonumber(hex_colour:sub(3, 4), 16),
tonumber(hex_colour:sub(5), 16)
end,

dim_color = function(colour, percent)
if colour == "NONE" then
return colour
end

local function hex_to_rgb(hex_colour)
return tonumber(hex_colour:sub(1, 2), 16),
tonumber(hex_colour:sub(3, 4), 16),
tonumber(hex_colour:sub(5), 16)
end

local function alter(attr)
return math.floor(attr * (100 - percent) / 100)
end

local r, g, b = hex_to_rgb(colour)
local r, g, b = module.public.hex_to_rgb(colour)

if not r or not g or not b then
return "NONE"
Expand Down
66 changes: 48 additions & 18 deletions lua/neorg/modules/core/integrations/image/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.load = function()
assert(success, "Unable to load image.nvim plugin")

module.private.image = image
module.private.image_utils = require("image.utils")
end

module.private = {
Expand All @@ -26,40 +27,69 @@ module.private = {

module.public = {
new_image = function(buffernr, png_path, position, window, scale, virtual_padding)
local geometry = {
x = position.column_start,
y = position.row_start + (virtual_padding and 1 or 0),
width = position.column_end - position.column_start,
height = scale,
}
local image = require("image").from_file(png_path, {
window = window,
buffer = buffernr,
inline = true, -- let image.nvim track the position for us
with_virtual_padding = virtual_padding,
x = position.column_start,
y = position.row_start + (virtual_padding and 1 or 0),
height = scale,
})
image:render(geometry)
end,
get_images = function()
return (require("image").get_images())
return image
end,
---Render an image or list of images
---@param images any[]
render = function(images)
for _, image in pairs(images) do
image:clear()
image:render()
for _, limage in pairs(images) do
limage.image:render({ y = limage.range[1], x = limage.range[2] })
end
end,
clear = function()
local images = module.public.get_images()
for _, image in pairs(images) do
image:clear()
clear = function(images)
for _, limage in pairs(images) do
limage.image:clear()
end
end,
clear_at_cursor = function(images, row)
for _, image in pairs(images) do
local cleared = {}
for id, limage in pairs(images) do
local image = limage.image
if image.geometry.y == row then
image:clear()
table.insert(cleared, id)
end
end
return cleared
end,
---Compute the image's rendered width/height without rendering
---@param image any an image.nvim image
---@param limit { width: number, height: number }
---@return { width: number, height: number }
image_size = function(image, limit)
limit = limit or {}
local term_size = require("image.utils.term").get_size()
local gopts = image.global_state.options

local true_size = {
width = math.min(
math.floor(image.image_width / term_size.cell_width), -- max image size (images don't scale up past their true size)
gopts.max_width or math.huge, -- image.nvim configured max size
limit.width or math.huge -- latex-renderer configured max size
),
height = math.min(
math.floor(image.image_height / term_size.cell_height),
gopts.max_height or math.huge,
limit.height or math.huge
),
}
local width, height = module.private.image_utils.math.adjust_to_aspect_ratio(
term_size,
image.image_width,
image.image_height,
true_size.width,
true_size.height
)
return { width = math.ceil(width), height = math.ceil(height) }
end,
}

Expand Down
Loading