obsidian.nvim icon indicating copy to clipboard operation
obsidian.nvim copied to clipboard

Code blocks with conceallevel

Open chris-dem opened this issue 11 months ago • 5 comments

I am trying to add code blocks to my documentation but due to the conceallevel, the backticks dissapear, is there a way to tell obsidian to overlay the backtick block because I would like to keep the rest of the UI features enabled

chris-dem avatar Mar 13 '24 14:03 chris-dem

I'd like this feature too.

I tried to fix this myself by adding an autocommand to check if the current line contains backticks and ignore the conceallevel, but I couldn't get it to work correctly.

aaronmcadam avatar Mar 14 '24 12:03 aaronmcadam

Is there any progress on the backticks? I was going to open an issue until I saw this one

aharoJ avatar Apr 13 '24 02:04 aharoJ

The workaround I'm currently using for this is to set a replacement character for the concealed triple backtick (```) Making the code block to look like this:

2024-06-27_13-48 2024-06-27_13-49

Still not ideal, but at least gives me an indication that this is a code block

I have configured a VimEnter autocmd for that:

vim.api.nvim_create_autocmd('VimEnter', {
  callback = function()
    vim.cmd [[
      augroup MarkdownSyntaxMatch
        autocmd!
        autocmd FileType markdown syntax match @conceal /```/ conceal cchar=⋯
      augroup END
    ]]
  end,
})

You can also set a different character for the triple backticks of the end of the codeblock by changing the match pattern:

syntax match @conceal /```\n/ conceal cchar=x

igorMSoares avatar Jun 27 '24 16:06 igorMSoares

I'm also suffering from this issue and I would really like a nicer solution to this problem. Maybe a way to only add concealing to your vault folder or a way to do some conceal "scaping".

@igorMSoares Thanks for the autocommand. Although it has a slight issue that when I have ```bash it will display the concealment characters 7 times, 3 for the backticks and 4 for bash. I tried playing around with the regex expression but I couldn't get it to work. Any ideas on how to fix this?

gfvioli avatar Jul 30 '24 08:07 gfvioli

@gfvioli I started noticing this issue just a couple of days after I commented here with the autocommand. Something has changed after that, that's why in the screenshot I posted the whole ```ts is replaced with the replacement character. Since then I haven't had the time to figure out why the behaviour has changed or to try any workaround. Looking forward to see if someone has got any ideas about it.

igorMSoares avatar Jul 30 '24 14:07 igorMSoares