Skip to content

feature: Thick borders for headers #123

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
serhez opened this issue Aug 7, 2024 · 7 comments
Closed

feature: Thick borders for headers #123

serhez opened this issue Aug 7, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@serhez
Copy link

serhez commented Aug 7, 2024

Is your feature request related to a problem? Please describe.

Thick borders are available for code blocks. Could they also be available for headers?

Describe the solution you'd like

This would require the two lines above and below a header to be empty, so that they can be used to render the thick border. This should not be an issue as standard markdown formatting conventions encourage this. However, it is perhaps good to check the corner case in which such lines are not available (i.e., first and last line of the document) or are not empty.

Describe alternatives you've considered

N/A.

Additional information

No response

@serhez serhez added the enhancement New feature or request label Aug 7, 2024
MeanderingProgrammer added a commit that referenced this issue Aug 7, 2024
# Details

Request: #123

This add a `heading -> border` field that is a boolean. This is slightly
different to code borders since it does not seem likely that different
styles will be implemented, more just off and on. The characters added
above and below are also configurable as new options.

The logic attempts to overlay the border on empty lines but will use
virtual text lines if the line is not available. Must also be aware of
the previous heading that was overlayed since that effectively makes a
line non empty as well.

This is essentially a port of the `fat_headlines` option in
headlines.nvim: https://github.com/lukas-reineke/headlines.nvim
@MeanderingProgrammer
Copy link
Owner

MeanderingProgrammer commented Aug 7, 2024

Feature added here: b700269

Can be enabled with:

require('render-markdown').setup({
    heading = { border = true },
})

There were other edge cases, like 2 headings back to back with only a line in-beween them like:

# Heading 1

## Heading 2

If we overlayed the bottom of the first and the top of the second they would overwrite each other.

Logic attempts to use an overlay but will use virtual lines to add space if it's not available.

Please update and LMK what you think

@serhez
Copy link
Author

serhez commented Aug 7, 2024

Thanks! I think it looks pretty amazing, it is visually much more clear now the boundaries between sections in my documents. Example on my setup:

Screenshot 2024-08-08 at 02 17 05

Screenshot 2024-08-08 at 02 16 33

Perhaps I would add a virtual line on top of the first heading if it was on the first line of the document (which is quite common I think), so that it looks consistent with the others.

The only other extra feature I could see is the possibility to also have level-dependent icons for the virtual lines, so for example the blocks I prepend could be extended to the extra lines. But, honestly, I'm nitpicking here and that feature may be annoying to implement (and also only benefit in very few cases, like using blocks as prefixing icons); this is pretty awesome already, thank you :)

@MeanderingProgrammer
Copy link
Owner

Perhaps I would add a virtual line on top of the first heading if it was on the first line of the document (which is quite common I think), so that it looks consistent with the others.

Virtual lines above the first line do not work quite how you would expect, this is a known issue in neovim: neovim/neovim#27967.

I actually do add it in either case and you can see it if you press <C-b>.

There's a similar issue with table borders when tables are on the first line, unfortunate but no real way around it.

level-dependent icons for the virtual lines

I think this would only make sense if you use block like icons, like in your case. So all I really need to do is apply the foreground highlight group for part of the line. Will see what I can do :)

MeanderingProgrammer added a commit that referenced this issue Aug 8, 2024
# Details

Request: #123

For heading borders some users use block characters. To improve the way
those look it would be nice if the color of the icon extended to the border.

Added the border_prefix option to do this. Highlights the border line
under the icon section with the foreground highlight group.

Minor bug fix for getting line below, did not update the if condition to
work correctly. Unnecessary virtual lines were being previously added.

Update CHANGELOG pre-release.
@MeanderingProgrammer
Copy link
Owner

MeanderingProgrammer commented Aug 8, 2024

Added support to highlight the border with the foreground underneath the heading here: 420058b

This is gated under the border_prefix option so you would now do:

require('render-markdown').setup({
    heading = {
        border = true,
        border_prefix = true,
    },
})

There was also a small bug in my previous implementation which would add unnecessary virtual lines underneath headings when it could have done an overlay, that's fixed as well.

@serhez
Copy link
Author

serhez commented Aug 8, 2024

That's great, thanks!

@pkazmier
Copy link

pkazmier commented Jan 5, 2025

Is there anyway to show the virtual line above line 1 when entering a markdown buffer so the L1 heading that starts on line 1 looks consistent with the rest of the headings in the buffer? Is there some way we can feed in a series of keys like: "gg"? Go to first line, Ctl-B, and then jump back to where cursor was when entering the file?

@pkazmier
Copy link

pkazmier commented Jan 5, 2025

Okay, I'm not a vim expert, but this gross hack seems to work for me.

-- HACK: to show the virtual text above line 1 for L1 headers.
vim.api.nvim_create_autocmd({ "BufReadPost" }, {
  pattern = "*.md",
  callback = function()
    local ctrl_y = vim.api.nvim_replace_termcodes("<c-y>", true, false, true)
    vim.schedule(function()
      local current_position = vim.api.nvim_win_get_cursor(0)
      vim.api.nvim_feedkeys(ctrl_y, "n", true)
      vim.api.nvim_win_set_cursor(0, current_position)
    end)
  end,
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants