Skip to content

feature: show language name above code blocks without icons #376

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
2 tasks done
ckjoris opened this issue Mar 23, 2025 · 4 comments
Closed
2 tasks done

feature: show language name above code blocks without icons #376

ckjoris opened this issue Mar 23, 2025 · 4 comments
Labels
enhancement New feature or request

Comments

@ckjoris
Copy link

ckjoris commented Mar 23, 2025

Neovim version (nvim -v)

0.10.2

Neovim distribution

n/a

Operating system

linux

Terminal emulator / GUI

guake

Describe the bug

the language name is not visible on top of markdown code blocks, for some languages,
like: 'racket', 'as3', or 'custom'. Its not fixed even if I set code = { enabled = false } in the config.atleast

Image

Image

test.md

Expected behavior

even if language is a rare or custom name, it should show the name.

Healthcheck output

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

render-markdown.nvim [version] ~
- OK plugin 8.1.8
- OK neovim >= 0.10

render-markdown.nvim [configuration] ~
- OK valid

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

render-markdown.nvim [icons] ~
- OK using: nvim-web-devicons

render-markdown.nvim [executables] ~
- OK latex2text: not installed

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

Plugin configuration

require("render-markdown").setup({
						overrides = {
							buftype = {
								nofile = { enabled = false },
							},
						},
						latex = { enabled = false },
						code = {
							-- Turn on / off code block & inline code rendering.
							enabled = true,
							-- style = 'none',
							style = "full",
							width = "block",
							-- left_pad = 0.2,
							right_pad = 0.2,
							min_width = 60,
							-- language_pad = 2,
							-- Whether to include the language name next to the icon.
							language_name = true,
							-- highlight_language = nil,
							sign = false
						},
						pipe_table = {
							-- Turn on / off pipe table rendering.
							enabled = true,
						},
						-- Checkboxes are a special instance of a 'list_item' that start with a 'shortcut_link'.
						-- There are two special states for unchecked & checked defined in the markdown grammar.
						checkbox = {
							-- Turn on / off checkbox state rendering.
							enabled = true,
							-- Additional modes to render checkboxes.
							render_modes = false,
							-- Determines how icons fill the available space.
							-- | inline  | underlying text is concealed resulting in a left aligned icon |
							-- | overlay | result is left padded with spaces to hide any additional text |
							position = "inline",
							unchecked = {
								-- Replaces '[ ]' of 'task_list_marker_unchecked'.
								icon = "󰄱 ",
								-- Highlight for the unchecked icon.
								highlight = "RenderMarkdownTodo", -- make it gray
								-- Highlight for item associated with unchecked checkbox.
								scope_highlight = nil,
							},
							checked = {
								-- Replaces '[x]' of 'task_list_marker_checked'.
								icon = "󰱒 ",
								highlight = "RenderMarkdownTodo", -- make it gray
								scope_highlight = nil,
							},
							-- Define custom checkbox states, more involved, not part of the markdown grammar.
							-- As a result this requires neovim >= 0.10.0 since it relies on 'inline' extmarks.
							-- The key is for healthcheck and to allow users to change its values, value type below.
							-- | raw             | matched against the raw text of a 'shortcut_link'           |
							-- | rendered        | replaces the 'raw' value when rendering                     |
							-- | highlight       | highlight for the 'rendered' icon                           |
							-- | scope_highlight | optional highlight for item associated with custom checkbox |
							custom = {
								todo = {
									raw = "[-]",
									rendered = "󰥔 ",
									highlight = "RenderMarkdownTodo",
									scope_highlight = nil,
								},
							},
						},
					})

Plugin error log

N/A

Confirmations

  • I have updated this plugin to the latest version using my plugin manager
  • I have provided the text contained in all screenshots as raw text in this issue. This means if there is a screenshot below it is the copy pasted contents of the file in the screenshot. I understand that my issue will be closed if I have not.

Additional information

No response

@ckjoris ckjoris added the bug Something isn't working label Mar 23, 2025
@MeanderingProgrammer
Copy link
Owner

Icons are retrieved from the icon provider, in your case nvim-web-devicons. If one isn't defined for the language then we have no icon to show.

@MeanderingProgrammer MeanderingProgrammer added not a bug Not a bug in this plugin and removed bug Something isn't working labels Mar 23, 2025
@ckjoris
Copy link
Author

ckjoris commented Mar 23, 2025

I don't care about icons, would disable them if I could. But problem is no language name is shown.

MeanderingProgrammer added a commit that referenced this issue Mar 25, 2025
… name

## Details

Request: #376

Adds configuration option `code.language_icon` which works with the
existing `code.language_name` option. This option is enabled by default
so the behavior is identical to what it was before.

This changes the behavior if an icon is not available for a particular
language. Rather than adding an empty border (old behavior) we now add a
line with just the language name. Since the icon provider previously
gave us the highlight to use and it could be missing, we now need a
fallback. This is set by the new `code.highlight_fallback` option which
by default links to the `Normal` highlight group.

To make this work is mostly minor implementation details. Continue
processing the language even if the icon returned from the provider is
missing. After creating the virtual text line check if it's empty before
adding it, this would happen if `language_name = false` and there is no
icon available.

Other minor differences in behavior, but these only impact users who do
NOT have the language details concealed, likely by NOT enabling
`nvim-treesitter` highlights + these options:

- `position = 'left'`: the language name is added after the icon, rather
  than being skipped by default, to avoid adding the name users will now
  have to set `language_name = false`, which will add only the icon
- `position = 'left'` + `language_padding > 0`: the padding is now
  added, previously we would skip adding the padding
@MeanderingProgrammer MeanderingProgrammer added enhancement New feature or request and removed not a bug Not a bug in this plugin labels Mar 25, 2025
@MeanderingProgrammer MeanderingProgrammer changed the title bug: codeblocks not rendering language name for some languages feature: show language name above code blocks without icons Mar 25, 2025
@MeanderingProgrammer
Copy link
Owner

Added the ability to disable icons here: 8ee2701

Use this configuration:

require('render-markdown').setup({
    code = { language_icon = false },
})

The behavior in general is a little different, so now if an icon isn't available we'll still show the language.

@ckjoris
Copy link
Author

ckjoris commented Mar 25, 2025

great stuff, cheers!

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