Skip to content

feature: Flexible width code blocks + right-aligned language hint #73

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 Jul 19, 2024 · 8 comments
Closed

feature: Flexible width code blocks + right-aligned language hint #73

serhez opened this issue Jul 19, 2024 · 8 comments
Labels
enhancement New feature or request

Comments

@serhez
Copy link

serhez commented Jul 19, 2024

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

Not a problem, just a suggestion :)

Describe the solution you'd like

I am using this plugin over markview.nvim because of many key reasons, including the lower amount of errors (e.g., with rendering nested bullet lists) and the ease of setting it up for non-markdown filetypes. However, I still really like the way code blocks are rendered in markview.nvim. Could some of those features be implemented here? Particularly:

  • Adaptable width for code blocks, depending on the width of the longest line in the block (with perhaps some minimum width). On this front, I have encountered some visual bugs in markview.nvim when wrapping lines that are too long, it seems to break the non-full-width code block render.
  • Fight-aligned language hint.
  • Right padding (currently there is only left padding); it would go well with the adaptable width feature.

Describe alternatives you've considered

No alternatives, the plugin is still great as-is ATM.

Additional information

No response

@serhez serhez added the enhancement New feature or request label Jul 19, 2024
@MeanderingProgrammer
Copy link
Owner

Right padding and adaptable width code blocks have been implemented in this PR: #88!

Use code = { width = 'block' } & code = { right_pad = x }.

I'll come back to implementing the right aligned language at some point. If I don't like any implementation I come up with will provide an update.

@garcia5
Copy link

garcia5 commented Jul 25, 2024

I just updated this plugin today, but the width = "block" option isn't quite working for me. It cuts off the background highlight at the correctly on the 1st/last lines of my code block, but is still full width for everything else.

Rendered code block

image

Plugin config

return {
    "MeanderingProgrammer/markdown.nvim",
    as = "render-markdown",
    main = "render-markdown",
    dependencies = {
        "nvim-treesitter/nvim-treesitter",
    },
    ft = {
        "markdown",
    },
    opts = {
        code = {
            style = "normal", -- {"none", "normal", "language", "full"} code blocks don't show language info in heading
            width = "block", -- {"block, "full"} only highlight relevant region instead of entire width
            right_pad = 2,
        },
    },
}

:checkhealth output

render-markdown: require("render-markdown.health").check()

markdown.nvim [neovim version] ~
- OK Version >= 0.10

markdown.nvim [configuration] ~
- OK valid

markdown.nvim [nvim-treesitter] ~
- OK installed
- OK markdown: parser installed
- OK markdown: highlight enabled
- OK markdown_inline: parser installed
- OK markdown_inline: highlight enabled
- OK latex: parser installed

markdown.nvim [executables] ~
- WARNING latex2text: not installed
  - ADVICE:
    - Disable LaTeX support to avoid this warning by setting { latex = { enabled = false } }

markdown.nvim [conflicts] ~
- OK headlines: not installed
- OK obsidian: not installed

Love the plugin BTW, let me know if I can add any additional info

@MeanderingProgrammer
Copy link
Owner

MeanderingProgrammer commented Jul 25, 2024

Oh that is strange, I am definitely not seeing the same behavior with the same config.

Can you send me the markdown file text from the screenshot, just so I can rule that out.

Otherwise I'll need some kind of minimal reproducible example which you would get by gradually disabling plugins and options. If the problem persists for instance, with only a plugin manager, nvim-treesitter, and my plugin that makes things a lot easier to reason about.

Also how does it look if you create a file with the following contents only:

```
print("Hello")
```

@garcia5
Copy link

garcia5 commented Jul 25, 2024

Good idea that it's another plugin interfering, it was my color scheme having "transparent background" set!

https://github.com/catppuccin/nvim?tab=readme-ov-file#configuration

With this setting disabled the code block renders as expected which is fine with me. Thanks!

@MeanderingProgrammer
Copy link
Owner

Interesting if you can find a way for me to create a transparent background with virtual text feel free to create a feature request for it.

Currently we hard code the highlight for the fixed width padding to Normal which is the background color of most color schemes: https://github.com/MeanderingProgrammer/markdown.nvim/blob/main/lua/render-markdown/handler/markdown.lua#L260.

It makes sense that a transparent background doesn't quite work with this. But if there is a transparent highlight group that exists I can make that highlight configurable.

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

Request: #73

Adds new field `code -> position` with valid values `left` & `right`.

Default value of `left` results in no change to current behavior.

Changing the value to right will move the language icon to align roughly
with the right side of the longest line in the code block. There is
slightly different positioning for `block` vs `full` widths.
@MeanderingProgrammer
Copy link
Owner

MeanderingProgrammer commented Aug 1, 2024

Support for right aligned language hint added here: 4d8b603

Enable it with:

require('render-markdown').setup({
    code = { position = 'right' },
})

I believe this completes all the requested features, feel free to re-open if it does not work as intended.

Thanks for the suggestions!

@benj9000
Copy link

benj9000 commented Oct 6, 2024

With above's snippet (#73 (comment)), I expected the language hint to be rendered aligned to the right of the window, but it depends on the length of the longest line in the code. Is that the intended behaviour?

image

I just started playing around with this plugin, such that this comment can be considered more of an FYI than a request.

@MeanderingProgrammer
Copy link
Owner

@benj9000, it is the intended behavior, since on particularly wide windows having it all the way to the right isn't a great experience, at least that would be my opinion.

I could add something where it would be all the way to the right up to some max width, or just all the way to the right. So if either of those seem interesting to you feel free to create a feature request :)

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

4 participants