jrblevin / markdown-mode

Emacs Markdown Mode
http://jblevins.org/projects/markdown-mode/
GNU General Public License v3.0
875 stars 160 forks source link

Provide a function to determine lang-mode #792

Open gekoke opened 10 months ago

gekoke commented 10 months ago

Currently, the mode for fenced code blocks is determined using the markdown-code-lang-modes alist. It maps the first occuring word in the infostring to a language mode.

This is generally fine, however, the CommonMark Spec doesn't say that this is how the infostring MUST be used:

The first word of the info string is typically used to specify the language of the code sample, and rendered in the class attribute of the code tag. However, this spec does not mandate any particular treatment of the info string.

Therefore, it would be nice if the mode could be determined using a user-defined function that takes the infostring as input.

I specifically ran into this corner case when using this MDX plugin that was using the infostring to add a title attribute to code blocks using the format lang:title.

For example:

def foo():
    pass

I would want to use python-mode in this case, even though the first word is py:Python.