|
1 | 1 | # Limitations
|
2 | 2 |
|
| 3 | +## `block` Width Removes Column Features |
| 4 | + |
| 5 | +[ISSUE #385](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/385) |
| 6 | + |
| 7 | +This problem impacts both `code` & `heading` rendering when using |
| 8 | +`{ width = 'block' }`. Regardless of how wide the actual content is all `colorcolumn` |
| 9 | +icons will be hidden on the intersecting lines and `cursorline` will not work. |
| 10 | + |
| 11 | +This occurs because there is no way to create a background highlight that starts |
| 12 | +and ends at specific columns. So instead to achieve the effect we combine 2 highlights: |
| 13 | + |
| 14 | +1. `hl_group` + `hl_eol`: results in the entire line being highlighted |
| 15 | +2. `virt_text` with many spaces using the background highlight + `virt_text_win_col`: |
| 16 | + results in hiding the highlight after our target column |
| 17 | + |
| 18 | +Why does it work like this? To explain that lets see how else we could implement |
| 19 | +this. The starting point would be to avoid highlighting the entire line, so we don't |
| 20 | +then need to hide the highlight. This part is easy, just remove `hl_eol = true` from |
| 21 | +the first mark, done! |
| 22 | + |
| 23 | +Now we have all the inner text highlighted with the background, so the problem is |
| 24 | +now to extend each one of these so it reaches our target column. |
| 25 | + |
| 26 | +Your first thought might be to use `virt_text_pos = 'eol'`, and do some basic math |
| 27 | +to figure out how long to make each line. Well, unfortunately `eol` does not mean |
| 28 | +right at the end of the line, there's actually a space that gets added before the |
| 29 | +mark starts that we cannot get rid of, so this one is a non-starter. |
| 30 | + |
| 31 | +Your second thought might be to use `virt_text_win_col`, but set it to be right after |
| 32 | +each line, after that it's the same as the previous approach. To make this work we |
| 33 | +need to compute the width of each line exactly. If we make it one too large we'll |
| 34 | +have an empty space, too small and we'll cut off text in the code block. To do this |
| 35 | +correctly we'll need to properly handle concealed ranges for all of the code blocks. |
| 36 | +This isn't impossible but it is slow and error prone since we also need to handle |
| 37 | +the odd case where another `markdown` block is nested. |
| 38 | + |
| 39 | +To avoid all this additional complexity we take the approach of using 2 highlights |
| 40 | +which works because the simple string width calculation is if anything going to be |
| 41 | +an over-estimate which is not really a big deal, just adds some extra padding in |
| 42 | +the worst case but the block remains contiguous. |
| 43 | + |
| 44 | +Below are a few things to try out to improve the aesthetic: |
| 45 | + |
| 46 | +- Use `win_options` to disable `colorcolumn` when rendering, this is my personal |
| 47 | + favorite since `colorcolumn` is really only helpful when editing |
| 48 | + |
| 49 | +```lua |
| 50 | +require('render-markdown').setup({ |
| 51 | + win_options = { |
| 52 | + colorcolumn = { default = '80', rendered = '' }, |
| 53 | + }, |
| 54 | +}) |
| 55 | +``` |
| 56 | + |
| 57 | +- Set the `min_width` options to the same value as `colorcolumn` |
| 58 | + |
| 59 | +```lua |
| 60 | +require('render-markdown').setup({ |
| 61 | + heading = { width = 'block', min_width = 80 }, |
| 62 | + code = { width = 'block', min_width = 80 }, |
| 63 | +}) |
| 64 | +``` |
| 65 | + |
| 66 | +- Do not use `block` width, keep the default value of `full` |
| 67 | + |
3 | 68 | ## `latex` Formula Positioning
|
4 | 69 |
|
5 | 70 | [ISSUE #6](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/6)
|
|
0 commit comments