SidOfc / mkdx

A vim plugin that adds some nice extra's for working with markdown documents
https://www.vim.org/scripts/script.php?script_id=5620
MIT License
482 stars 13 forks source link

[Feature request] Highlight code inside code block #149

Closed Mayrixon closed 3 years ago

Mayrixon commented 3 years ago

Hello, I'm wondering if it is the design philosophy that it doesn't provide code highlighting inside code blocks. If it's not, is that possible to provide code highlighting?

As I know, both plugin tpope/vim-markdown and plugin plasticboy/vim-markdown provide code highlighting. Besides, Typora, a famous markdown editor, also provides code highlighting.

If you are concerning about the disruption of highlighting codes, here is a solution I'm using. I added the following snippet into my vim configuration, which is from tpope/vim-markdown.

let g:markdown_fenced_languages = ['python', 'rust']

if !exists('g:markdown_fenced_languages')
  let g:markdown_fenced_languages = []
endif
let s:done_include = {}
for s:type in map(copy(g:markdown_fenced_languages),'matchstr(v:val,"[^=]*$")')
  if has_key(s:done_include, matchstr(s:type,'[^.]*'))
    continue
  endif
  if s:type =~ '\.'
    let b:{matchstr(s:type,'[^.]*')}_subtype = matchstr(s:type,'\.\zs.*')
  endif
  exe 'syn include @markdownHighlight'.substitute(s:type,'\.','','g').' syntax/'.matchstr(s:type,'[^.]*').'.vim'
  unlet! b:current_syntax
  let s:done_include[matchstr(s:type,'[^.]*')] = 1
endfor
unlet! s:type
unlet! s:done_include
SidOfc commented 3 years ago

Hi @Mayrixon, it is because mkdx does not need to implement this. You can enable this by setting let g:markdown_fenced_languages in your .vimrc already. Mkdx does not replace the default markdown files (vim-markdown) but rather, adds more functionality on top of what it already offers.

To enable python and rust highlighting you only need:

let g:markdown_fenced_languages = ['python', 'rust']

You can get rid of the rest of the code since vim-markdown already handles it internally. I'll close this issue for now, let me know if you encounter any issues.

EDIT

Keep in mind that on large files this can slow down vim quite a bit, this is not something I can fix or improve through mkdx.