-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Figure out how to handle concealed text consistently #50
Comments
For the concealed language issue I've made up the following custom handler custom_handlers = {
markdown = {
render = function(namespace, root, buf)
-- check for the concealed language node for code blocks
local icons = require("render-markdown.icons")
query = vim.treesitter.query.parse("markdown", "(info_string (language) @_lang)")
for _, node in query:iter_captures(root, buf) do
local value = vim.treesitter.get_node_text(node, buf)
local icon, icon_highlight = icons.get(value)
if icon == nil or icon_highlight == nil then
return
end
local start_row, start_col = node:range()
local captures = vim.treesitter.get_captures_at_pos(buf, start_row, start_col)
local is_consealed = false
for _, capture in ipairs(captures) do
if capture.metadata.conceal then
is_consealed = true
end
end
local icon_text
if is_consealed then
icon_text = { icon .. " " .. value, { icon_highlight, "ColorColumn" } }
else
-- if the language isn't concealed, keep users preferences intach, only the icon will be added
icon_text = { icon .. " ", { icon_highlight, "ColorColumn" } }
end
vim.api.nvim_buf_set_extmark(buf, namespace, start_row, start_col, {
virt_text = { icon_text },
virt_text_pos = "inline",
})
end
end,
extends = true,
},
}, In the plugin configuration was added Please note that we need Treesitter captures rather than I suppose this might give you some ideas on how to solve the problem more generally |
I've added a version of your solution as part of this commit: 9b7fdea. The change I made was focussed on getting tables working well, so that I wasn't just overlaying text. This change fit nicely in there since I needed to make calculating concealed text more generic. LMK if it works for you! I still need to go through and think of any other places to apply this, such as handling users that conceal heading |
Yes this works, thanks. If heading Concerning tables and links icons: for my configuration they don't work together. pipe_table = { cell = "raw" }
Here is code:
The are a few options how to remediate the situation:
At the moment I have to completely disable this feature, despite the fact that it would be very useful for regular text. link = { enabled = false } I'm sticking with the assumption that enabling the plugin shall improve default rendering rather than requiring content to be reformatted. |
No matter the approach taken, if you want tables to look nice with this plugin you will need to format the underlying text to some extent as well. Like in your example you're essentially manually computing concealed text length so things line up when rendered. Table rendering can be disabled as well with For your example table it'll work if you use
I wouldn't quite characterize the problem as I do agree the raw table rendering calculation for The example you provided now almost works with
Not having links in tables is a little tricky, may add that later. The problem is that the |
Pushed a fix for user concealed headings here: 5ce3566. Marking this as done as it seems to handle the cases I've tested out relatively well. We have re-usable code to apply elsewhere if similar issues crop up or if there are some bugs with the implementation. |
There are various aspects of this plugin that assume default settings and default highlights for concealing.
When this is not the case we end up overwriting or duplicating text, neither of which is good.
Anything to do with alignment will need to be looked over and work with no concealing, full concealing, and character replacement concealing.
The text was updated successfully, but these errors were encountered: