-
Notifications
You must be signed in to change notification settings - Fork 41
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
feature: styling for bare URLs & comments #244
Comments
For bare URLs are you talking about actual bare URL, like I'll add support for the latter, but will probably handle it more like emails where the angle brackets are hidden and an icon is added rather than hiding the whole thing. For the former since these are not handled by the treesitter parser I'm not going to handle them. I've generally stayed away from touching any HTML entities, but maybe comments are a good exception to this. I'll provide a |
That makes sense, as markdownlint as well as some parsers expect angel brackets, making it somewhat the idiomatic way of writing urls (https://github.com/updownpress/markdown-lint/blob/master/rules/034-no-bare-urls.md)
yep, that sounds good! |
## Details Request: #244 Bare URLs in angle brackets are parsed by treesitter into a uri_autolink node. Add support for this node type in our link renderer. Use the icon based on the destination. Functions similarly to emails in that the angle brackets are hidden while the link contents are still displayed with the addition of the icon.
Bare URL support added here: 401a6c9 |
Here's what a custom handler for concealing HTML comments would look like: ---@param root TSNode
---@param buf integer
---@return render.md.Mark[]
local function hide_comments(root, buf)
local marks = {}
local query = vim.treesitter.query.parse('html', '(comment) @comment')
for id, node in query:iter_captures(root, buf) do
local capture = query.captures[id]
local start_row, start_col, end_row, end_col = node:range()
if capture == 'comment' then
table.insert(marks, {
conceal = true,
start_row = start_row,
start_col = start_col,
opts = { end_row = end_row, end_col = end_col, conceal = '' },
})
end
end
return marks
end
require('render-markdown').setup({
custom_handlers = {
html = { parse = hide_comments },
},
}) |
Thanks! I prefer having them not completely hidden, but I realized that it's just the
Thanks, looks like a charm! There appears to a visual glitch when passing such bare URLs though, which does not happens with other conceals by this plugin: Pasted.image.2024-12-03.at.22.12.22.mp4 |
## Details Problem mentioned here: #244 For autolinks (emails & bare URLs) just like with wiki links we conceal all of the text then inline a modified version with our icon using a single extmark. This works but for longer strings can make things look choppy when removing the mark under the cursor row. To improve this for autolinks we'll instead split the one mark into 4 separate smaller ones: - Conceal the starting '<' - Conceal the ending '>' - Inline the icon at the start - Apply highlight over the link text Doing the same thing for wiki links would be more complicated to support aliases so will leave those as is for now.
That definitely doesn't look good. Out of curiosity what terminal emulator / GUI are you running neovim in? To remove the angle brackets and add the icon I used a single extmark that hid the entire line then added it back inlined with icon plus the URL minus brackets. Since that's effectively removing and adding back the entire line it ends up having this pretty bad behavior. Fixed this here hopefully: b6b903c. Separated the logic into 4 smaller marks to hide brackets, add the icon, and highlight the URL. Can you update and LMK if it's better on your end, I'm not able to replicate that behavior on my end. |
## Details Request: #244 Use `html` parser to find and conceal comment nodes.
Added support for concealing HTML comments here: 558310a |
Thank you! The glitch has been fixed, and the html comments also work. A small suggestion: would it be possible to optionally set an icon as conceal character, instead of completely hiding the comments? Having them completely out of sight can be a bit confusing |
## Details Request: #244 Previously support was added for html comment concealing gated by the `html.conceal_comments` option. A request to add some kind of icon next to the now concealed text was made so I'm breaking this configuration, should be very minimal impact and having an older version won't fail. Now we have an `html.comment` configuration which stores a `conceal` boolean and functions like the previous option. Additionally an optional `text` field is added along with a `highlight` to use for this text. By default the `text` field is made nil, so we don't do anything more by default than before. If a user specifies some string we inline this at the start of the now concealed comment with the `highlight` specified or the default which naturally links to `@comment`. Since this is inline text and not a conceal character users are free to make it arbitrarily long or use a single icon, all should work without a problem. Refactored HTML handler to match markdown & markdown_inline approach.
Sure added support for this here: 7674543 By default no value is set so it will still just conceal the comment out of the box. You just need to provide a value for require('render-markdown').setup({
html = { comment = { text = 'SOME VALUE' } },
}) I used inline text rather than a conceal character so you're free to use a value as long or short as you want. |
Perfect, thank you! |
Just send you a small coffee (or two, depending on where you live) for all your awesome work and quick responses. Cheers! |
Hi, shouldn't be this opt-in instead of opt-out? IMO concealing content is kind of intrusive and really a personal preference. Anyway, is nice to see that is easy to restore the old behavior: opts = {
html = { comment = { conceal = false } },
}, |
I see it in the same way as concealing links and other content that's concealed out of the box. HTML comments are the same level of information as a link URL. If concealing content is intrusive you can opt out of it via: opts = {
win_options = { conceallevel = { rendered = 0 } },
} In which case the HTML comment concealing would also be disabled. Otherwise it's a case by case thing that is left up to you to decide. In general all new features that aren't new options for an existing feature will be enabled by default with some way to opt out. |
Is your feature request related to a problem? Please describe.
This plugin really has come a long way, congrats for that.
The only two things I noticed that are not handled by the plugin yet are
<!-- toc -->
and bare URLs.Describe the solution you'd like
I think in both cases, bare URLs and comments, they could be concealed, with only one icon left to indicate the presence of content maybe?
Describe alternatives you've considered
I am not aware of any.
Additional information
No response
The text was updated successfully, but these errors were encountered: