-
Notifications
You must be signed in to change notification settings - Fork 49
feature: Highlight text background when double = on each side #173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, I assume you're talking about this feature of Obsidian: https://help.obsidian.md/Editing+and+formatting/Basic+formatting+syntax#Bold,%20italics,%20highlights. I rely on tree-sitter to do the entirety of the document parsing and am not open to doing line by line string parsing to implement features, for my own sanity. Since the Appreciate the idea, is sometimes hard to explain why some seemingly easy tasks are hard and vice versa. The other features in that Obsidian document are handled by the |
thanks for your response, didnt know this was not standard, do you know if somehow i can do that in my side like a code snippet ? Im still not neovim tech savy, hence the question. obsidian.nvim implement this highlight feature if i turn on their ui plugin config, but i keep it disable because it mess with your plugin ui, and your ui is better |
Sure, you can use the extension point of this plugin called require('render-markdown').setup({
custom_handlers = {
markdown = {
extends = true,
parse = function(root, buf)
local marks = {}
---@param row integer
---@param start_col integer
---@param end_col integer
---@param conceal? string
---@param hl_group? string
local function append(row, start_col, end_col, conceal, hl_group)
table.insert(marks, {
conceal = true,
start_row = row,
start_col = start_col,
opts = { end_row = row, end_col = end_col, conceal = conceal, hl_group = hl_group },
})
end
local start_row = root:range()
local text = vim.treesitter.get_node_text(root, buf)
for i, line in ipairs(vim.split(text, '\n', { plain = true })) do
local row = start_row + i - 1
---@type integer|nil
local position = 1
while position ~= nil do
local start_col, end_col = line:find('(=)=[^=]+=(=)', position)
if start_col ~= nil and end_col ~= nil then
-- Translate 1 based index to 0 based index, update position
start_col, position = start_col - 1, end_col + 1
-- Hide first 2 equal signs
append(row, start_col, start_col + 2, '', nil)
-- Highlight contents
append(row, start_col, end_col, nil, 'DiffDelete')
-- Hide last 2 equal signs
append(row, end_col - 2, end_col, '', nil)
else
position = nil
end
end
end
return marks
end,
},
},
}) |
This is now handled natively by the plugin after: d6a82d7 |
Is your feature request related to a problem? Please describe.
In some markdown apps, like obsidian, if you do a double = between a text it would highlight the text, with yellow background (and also turn black the letter color) and would hide the double = on each side
like ==some text here==
would become :
like some text here (with yellow background and dark letter color)
Describe the solution you'd like
hide the double = on each side and paint the background color with yellow (could be a custom color) and paint the letter with black color
Describe alternatives you've considered
none
Additional information
thanks in advance, it is a amazing plugin so far
The text was updated successfully, but these errors were encountered: