Skip to content
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

🐞 Bug: Code blocks language parsing from info string only works for 3 backticks without spaces #234

Closed
2 tasks done
noirbizarre opened this issue Jan 3, 2025 · 13 comments · Fixed by #238
Closed
2 tasks done
Assignees
Labels
bug Something isn't working

Comments

@noirbizarre
Copy link
Contributor

noirbizarre commented Jan 3, 2025

Before reporting:

  • Ensure that the issue is reproducable on the main branch.
  • Ensure that there isn't an issue on this(either open or closed).

Problem:

Language parsing from code block info string is broken when not exactly 3 backticks followed by language without space.
According to CommonMark specs (so this also includes, GFM, GLFM, Myst and Obsidian which are all based on CommonMark):

  • a code fence is either a sequence of backticks or tilde
  • can have spaces between the fence and the info string
  • can have more than 3 backticks (this is required for nested fences like the Markdown code block below 👇🏼)

Steps to reproduce the issue:

Just try the following markdown snippet

Sample markdown

##### Tilde fence

~~~html
<strong>hello</strong>
~~~

##### spaces after fence

``` html
<strong>hello</strong>
```

```  html
<strong>hello</strong>
```

##### More than 3 backticks

``````html
<strong>hello</strong>
``````

Github rendering

Tilde fence
<strong>hello</strong>
spaces after fence
<strong>hello</strong>
<strong>hello</strong>
More than 3 backticks
<strong>hello</strong>

Markview rendering

image

As you can see:

  • tilde fence info string is ignored
  • info string with leading spaces render the type at the wrong place
  • With more than 3 backticks, extra backticks are taken into the type

Expected behavior:

In all 3 cases, language is properly parsed from the info string (starts after the fence, whatever its size, leading spaces ignored and works with tilde fence).

Bonus if it works with Markdown-It custom containers, Markdown-It-Py containers and Myst directives colon fence

Neovim version:

0.10.3

@noirbizarre noirbizarre added the bug Something isn't working label Jan 3, 2025
@noirbizarre noirbizarre changed the title 🐞 Bug: 🐞 Bug: Code blocks language parsing from info string only works for 3 backticks without spaces Jan 3, 2025
OXY2DEV added a commit that referenced this issue Jan 7, 2025
@OXY2DEV
Copy link
Owner

OXY2DEV commented Jan 7, 2025

It's fixed(on dev)!

Screenshot_2025-01-08-00-32-21-597_com termux-edit

@noirbizarre
Copy link
Contributor Author

Oh, you already provided a fix on dev, I just submitted a pull-request for main, sorry.

I just tested dev, it is totally broken on my setup (there seem to be some issues with the highlighter as well as some conflict with Snacks).

@OXY2DEV
Copy link
Owner

OXY2DEV commented Jan 8, 2025

it is totally broken on my setup

Which part of it is broken?

@noirbizarre
Copy link
Contributor Author

At first, It seems to conflict with Snacks indent (not sure this is the root cause but I have this error):

Error in decoration provider treesitter/highlighter.line:
Error executing lua: /usr/share/nvim/runtime/lua/vim/treesitter/query.lua:797: No handler for conceal-patch!
stack traceback:
	[C]: in function 'error'
	/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:797: in function 'fn'
	/usr/share/nvim/runtime/lua/vim/func/_memoize.lua:58: in function 'apply_directives'
	/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:892: in function 'iter'
	/usr/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:313: in function 'fn'
	/usr/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:213: in function 'for_each_highlight_state'
	/usr/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:294: in function 'on_line_impl'
	/usr/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:370: in function </usr/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:364>
	[C]: in function 'nvim_exec2'
	vim/_editor.lua: in function 'cmd'
	....local/share/nvim/lazy/snacks.nvim/lua/snacks/indent.lua:533: in function ''
	vim/_

When I deactivate Snack I have this error:

Failed to source `/home/noirbizarre/.local/share/nvim/lazy/markview.nvim/plugin/markview.lua`

vim/_editor.lua:0: /home/noirbizarre/.config/nvim/init.lua..nvim_exec2() called at /home/noirbizarre/.config/nvim/init.lua:0../home/noirbizarre/.local/share/nvim/lazy/markview.nvim/plugin/markview.lua: Vim(source):E5113: Error while calling lua chunk: ...hare/nvim/lazy/markview.nvim/lua/markview/highlights.lua:441: Invalid highlight color: '#19198000000000000000'
stack traceback:
^I[C]: in function 'nvim_set_hl'
^I...hare/nvim/lazy/markview.nvim/lua/markview/highlights.lua:441: in function 'create'
^I...hare/nvim/lazy/markview.nvim/lua/markview/highlights.lua:1552: in function 'setup'
^I....local/share/nvim/lazy/markview.nvim/plugin/markview.lua:23: in main chunk
^I[C]: in function 'nvim_exec2'
^Ivim/_editor.lua: in function 'cmd'
^I...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:510: in function <...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:509>
^I[C]: in function 'xpcall'
^I.../.local/share/nvim/lazy/lazy.nvim/lua/lazy/core/util.lua:135: in function 'try'
^I...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:509: in function 'source'
^I...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:457: in function 'source_runtime'
^I...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:425: in function 'packadd'
^I...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:359: in function '_load'
^I...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:197: in function 'load'
^I...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:127: in function 'startup'
^I...zarre/.local/share/nvim/lazy/lazy.nvim/lua/lazy/init.lua:112: in function 'setup'
^I/home/noirbizarre/.config/nvim/lua/setup/lazy.lua:18: in main chunk
^I[C]: in function 'require'
^I/home/noirbizarre/.config/nvim/init.lua:2: in main chunk

# stacktrace:
  - vim/_editor.lua:0 _in_ **cmd**
  - ~/.config/nvim/lua/setup/lazy.lua:18
  - ~/.config/nvim/init.lua:2

@OXY2DEV
Copy link
Owner

OXY2DEV commented Jan 8, 2025

Which colorscheme are you using?

@noirbizarre
Copy link
Contributor Author

Solarized Osaka with those settings:

    --- Solarized Osaka
    --- https://github.com/craftzdog/solarized-osaka.nvim
    {
        "craftzdog/solarized-osaka.nvim",
        lazy = false,
        priority = 1000,
        config = function()
            require("solarized-osaka").setup({
                transparent = true, -- Disable setting background
                dim_inactive = true, -- Non focused panes set to alternative background
                styles = {
                    sidebars = "transparent",
                },
            })

            vim.cmd("colorscheme solarized-osaka")
        end,
    },

@OXY2DEV
Copy link
Owner

OXY2DEV commented Jan 8, 2025

At first, It seems to conflict with Snacks indent

I think you are loading sancks.nvim before markview.nvim(or lazy loading markview.nvim) which is causing this issue.

@noirbizarre
Copy link
Contributor Author

Yes, Snack is one of the first loaded plugin (on purpose) due to some early dependencies I have on it (including debugging facilities).
markview is not lazy loading.

OXY2DEV added a commit that referenced this issue Jan 8, 2025
@OXY2DEV
Copy link
Owner

OXY2DEV commented Jan 8, 2025

The highlight issue is fixed.

Screenshot_2025-01-08-09-57-20-569_com termux-edit

@OXY2DEV
Copy link
Owner

OXY2DEV commented Jan 8, 2025

Yes, Snack is one of the first loaded plugin (on purpose) due to some early dependencies I have on it (including debugging facilities). markview is not lazy loading.

What happens if you add markview as a dependency to snacks.nvim?

@noirbizarre
Copy link
Contributor Author

Still the same issue even as a dependency.
I'll do further trials tomorrow (given I am interested in contributing, I need dev working)
I'll open a separate issue for this if I don't find a solution

@OXY2DEV
Copy link
Owner

OXY2DEV commented Jan 8, 2025

That's strange.

Unless snacks.nvim is modifying them it should be available.

What's your snacks.nvim config?

@OXY2DEV
Copy link
Owner

OXY2DEV commented Jan 8, 2025

I have tested with snacks.nvim's indent guides and it's working fine.

So, it's most likely something else in your config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants