Skip to content

Maintain custom highlights inside tables #21

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

Closed
mpasa opened this issue May 18, 2024 · 7 comments
Closed

Maintain custom highlights inside tables #21

mpasa opened this issue May 18, 2024 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@mpasa
Copy link

mpasa commented May 18, 2024

It seems that custom highlights are lost when matched inside a table cell.

Example document:

# test

foo

| Column1 |
| ------- |
| foo     |

Add the syntax and highlights:

syn match Custom "foo"
highlight Custom guifg=red

Output when editing is showing the styles as expected:

image

But normal mode rendering is removing the highlight inside the table:

image
@MeanderingProgrammer
Copy link
Owner

Make sense.

Since we overlay the entire row with the Normal mode highlight it ends up overwriting any syntax in the cells.

@MeanderingProgrammer MeanderingProgrammer self-assigned this May 19, 2024
@MeanderingProgrammer MeanderingProgrammer added the bug Something isn't working label May 19, 2024
@MeanderingProgrammer
Copy link
Owner

While this is possible to do I'm finding that handling concealing is a problem.

Meaning when we have a link or inline code block in a row, it will get concealed as part of rendering which will misalign the table: like so:

misaligned

Currently this is not a problem since the virtual text that gets overlayed includes all of the raw content without any concealing like so:

current

Between these 2 options I definitely prefer the latter.

My thought now is to add the ability to disable rendering of tables entirely if users prefer looking at the highlighted version.

Lmk if you have any thoughts / suggestions.

@mpasa
Copy link
Author

mpasa commented May 21, 2024

Is highlight linked to concealing in this case? I'm okay without any conceal, but the links can still be highlighted like in insert mode. So, the same number of rendered cells, but with proper colors. If it's linked and cannot be dettached, I will be also okay with disabling formatting for tables.

@MeanderingProgrammer
Copy link
Owner

Concealing is a general behavior of this plugin, added here: #10.

The conceal level gets changed between the rendered view and raw view. As far as I'm aware there is no way to scope options like that to a specific range in a window, so they need to apply to the entire window. Since a table cell can contain any markdown, including links, is just another thing to consider.

I'll add a way of disabling table rendering.

MeanderingProgrammer added a commit that referenced this issue May 21, 2024
# Details

* fat_tables option removed
* table_style option added
* If fat_tables option was not being set default behavior
  remains the same
* If fat_tables option was set to false setting table_style
  option to 'normal' will result in the same behavior
* Setting table_style to 'none' is new behavior and will stop
  rendering markdown tables: #21
@mpasa
Copy link
Author

mpasa commented May 21, 2024

I see. I see this already happens with normal treesitter with concealling enabled. I suppose the only solution would be to modify the nvim-treesitter highlights (here), but that'd be a ton of work.

@MeanderingProgrammer
Copy link
Owner

Added the new behavior here: 49f4597

You can now configure the plugin with:

{ table_style = 'none' }

In terms of modifying treesitter directly, apart from the effort, that would end up changing the behavior for everyone, and it does end up just being a preference as opposed to correct / incorrect behavior.

Hopefully this offers a decent middle ground though.

@mpasa
Copy link
Author

mpasa commented May 22, 2024

Amazing! Thank you very much, closing the issue now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants