Skip to content

help: Post-render callback #248

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
nmder opened this issue Dec 5, 2024 · 3 comments
Closed

help: Post-render callback #248

nmder opened this issue Dec 5, 2024 · 3 comments
Labels
question Further information is requested

Comments

@nmder
Copy link

nmder commented Dec 5, 2024

Neovim version (nvim -v)

0.10.2

Neovim distribution

N/A

Description

Hi there,

I was looking to render the latex formulas with nabla.nvim. I got it working thanks to the instructions on this repo and some modification to the nabla.nvim plugin. However, the latex must be rendered after rendering the markdown to account for the icon width, indentation, etc. Is there any way to achieve a post-render callback to achieve this?

I tried the usual on.attach callback, but it does not work as the callback happens much earlier.

Thanks in advance!

@nmder nmder added the question Further information is requested label Dec 5, 2024
@MeanderingProgrammer
Copy link
Owner

Can you provide a screenshot of how it looks now, preferably one with some obvious problems. Along with the configuration for both this plugin and nabla.

@nmder
Copy link
Author

nmder commented Dec 6, 2024

Sorry for the delayed response.

Here is the render with the next config:
image

  {
    "MeanderingProgrammer/render-markdown.nvim",
    ft = { 'markdown' },
    dependencies = {
      'nvim-tree/nvim-web-devicons',
      'nvim-treesitter/nvim-treesitter',
      'nmder/nabla.nvim',
    },
    config = function ()
      vim.api.nvim_set_hl(0, 'myRenderMarkdownCode', { bg = '#22252B' })
      require('render-markdown').setup {
        latex = { enabled = false },
        render_modes = { 'n', 'c', 't', 'i' },
        win_options = { conceallevel = { rendered = 2 } },
        on = {
          attach = function()
            -- vim.defer_fn(
            --   function ()
                require('nabla').enable_virt({ autogen = true })
              -- end, 100)
          end,
        },
        sign = {
          enabled = false,
        },
        code = {
          highlight = 'myRenderMarkdownCode',
        }
      }
    end
  },

In the line 3 of the above screenshot, you may notice that the exponents x are above the base. This is caused by a lack of accounting of the concealed and inline virtual texts added by render-markdown.

Now, with the commented part in the above config, with defer_fn, I am scheduling a delayed rendering by nabla (a modded version as the existing repo does not work well, as it is parsing the document as a latex file to identify the math zones which is messing up code blocks with shell variables; the original also did not account for the concealed and inline virtual text to properly place the exponents in the virtual line above). This generates the following proper rendering:
image

Same results can be achieved by entering and exiting insert mode on a line without an affected math environment.

Therefore, a post-render callback could be useful to achieve a proper rendering pipeline.

MeanderingProgrammer added a commit that referenced this issue Dec 7, 2024
## Details

Request: #248

Adds `on.render` callback which is executed after this plugin finishes
rendering a buffer.

This happens after every render cycle, users should be aware that it
will likely be called many times for a given buffer and use it with that
in mind.
@MeanderingProgrammer
Copy link
Owner

Gotcha, makes sense. Added on.render option here: c89e5e0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants