preservim / vim-markdown

Markdown Vim Mode
4.69k stars 524 forks source link

Capitalized fenced code block languages aren't handled properly #618

Open ElnuDev opened 1 year ago

ElnuDev commented 1 year ago

There's an issue with how capitalization is handled in fenced code blocks. In my configuration, I've set rs to be associated with Rust:

let g:vim_markdown_fenced_languages = ['rs=rust']

However, if I open a markdown file and enter the following:

```RS
fn amogus() {
  println!("sus");
}


The Rust code won't highlight, even if I close and reopen the file. At first I thought this is because `vim_markdown_fenced_languages` is case sensitive, but this turned out to not be the case, because the code is rendered correctly as soon as any non-capitalized code block is added. In fact, switching `RS` to `rs` and then putting it back again will also fix the issue for a single session.

This same issue happens for file types not added to `vim_markdown_fenced_languages`.
alerque commented 1 year ago

What markdown spec allows capitalized names? As far as I know all the parsers agree fully lowercased names are the canonical form. I don't even think VIM will accept that as a filetype, we'd have to do the case casting ourselves instead of just passing it through.

ElnuDev commented 1 year ago

The CommonMark spec "doesn’t mandate any particular treatment of the info string" according to its documentation , so I don't think there's any reason to think they're disallowed. Even if lowercased names are considered canonical, they still work in every single parser I've used, including GitHub's. Shouldn't the plugin agree with parser outputs? I don't really see any disadvantage in having capitalized info strings work properly, not having them work properly just makes vim-markdown appear broken for people who use a convention of capitalizing language names.

It's not like vim-markdown doesn't render capitalized names at all anyway, it just acts buggy when they're around, being temperamental whether or not it decides to highlight them.

alerque commented 1 year ago

Okay, if other parsers normalize this I suppose we can too. The VIM filetypes we have to map to are all lower case, but I'd be happy to facilitate a PR that normalizes these before passing them to VIM.

ElnuDev commented 1 year ago

Alright! I'll make a PR soon.