Skip to content

Set padding character for inline code #389

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
danielyrovas opened this issue Apr 2, 2025 · 4 comments
Closed

Set padding character for inline code #389

danielyrovas opened this issue Apr 2, 2025 · 4 comments
Labels
enhancement New feature or request

Comments

@danielyrovas
Copy link

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

I'd like to be able to set the padding character for an inline code segment: inline code

I currently set the padding value to 1 and this highlights it with a square background.

I'd like to use a character like this (might need to view it by pasting into terminal):

to enable making the background a rounded shape.

Describe the solution you'd like

An option to set a left & right padding character, alongside any necessary highlights

Describe alternatives you've considered

leaving it as a square (which is still nice 🥇)

Additional information

No response

@danielyrovas danielyrovas added the enhancement New feature or request label Apr 2, 2025
MeanderingProgrammer added a commit that referenced this issue Apr 3, 2025
## Details

Request: #389

Allows users to set text values for `code.inline_left` &
`code.inline_right` which will be added to the left and right of inline
code blocks. Will be combined with `code.inline_pad`. Example using half
circles:

```lua
require('render-markdown').setup({
    code = { inline_left = '', inline_right = '' },
})
```

Highlight gets created by inverting the padding highlight in a similar
way we do for `thin` code borders.

Minor other change, re-order class definitions to be top down.
@MeanderingProgrammer
Copy link
Owner

Done: b292624

Example:

require('render-markdown').setup({
    code = { inline_left = '', inline_right = '' },
})

Highlight should work out of the box by inverting the one used for the background so that value is not configurable.

You can still modify code.highlight_inline to whatever value you want to change the background.

Neat suggestion, thanks!

@danielyrovas
Copy link
Author

Wow, that is exactly what I imagined👌, perfect, thank you!

@danielyrovas
Copy link
Author

Hey this looks a little weird when used in a heading/title, as that sets a background, and the background colour of the padding character is left as the default background, rather than the colour of the heading's background.

Do you think it would be possible to either remove the padding character if there is a background from a heading (so the highlight becomes square), or set the background colour of the padding character to match the background colour of the heading (to keep it rounded)?

Image

@MeanderingProgrammer
Copy link
Owner

Matching the background based on context just isn't practical, it makes things a lot more complicated for various reasons.

There is a property I can set on extmarks, hl_mode = 'combine', which we use for links, and allows neovim to effectively do this. I tried it out for inline code blocks and, while it fixes things in headings, it breaks them outside of headings. Here's what it ends up looking like:

Image

As you can see headings look correct but the one one in the paragraph becomes a square.

The reason this happens is in headings I'm setting the background, however outside of headings, inline code blocks get assigned a highlight group from treesitter and since the end of the inline code block intersects with the icon the background from the node is used. I'm not 100% sure why it doesn't happen at the start as well but if I had to guess it's because text inlined at the start of a node appears before the node whereas text inlined at the end of a node appears inside the node.

Anyway, for the time being I don't plan on changing it as favoring one makes the other worse and I'm assuming inline code blocks happen more often in paragraphs than headings. If you want to send a PR with an improvement more than happy to take a look!

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

2 participants