NodeBB/nodebb-plugin-markdown

Ability to set a default highlight language instead of autodetection

Closed this issue · 5 comments

T3P3 commented

Most users on out forum do not know to set the code syntax highlighting to a specific language (which make sense as its not a supported language anyway, however JSON works quite nicely as a substitute formatting).

It would be great if there was an option to override the highlight.js autodetect and insert a hardcoded language into every code block. The hard coded language format could be set in the markdown plugin settings, the user could over ride it if they wished (by replacing the ` ` `JSON or whatever with what they wanted

Hi there @T3P3

Thanks for the suggestion, it is a good one, and I will look into implementing it.

A complication exists in that highlight.js it may not be actually used directly, but might be called as a markdown plugin, which might make it a dependency of a dependency of a dependency... 😬

We shall see.

pitaj commented

I'm confused. It seems like you already can set the language manually with

```lang

https://community.nodebb.org/post/85843

@pitaj I believe the issue here is that there is no way to set a default language (or rather, it tries to autodetect a language if none is explicitly passed in).

@T3P3 is asking for that to be added, if his users are unaware that a language can be manually set.

T3P3 commented

Yes that's is exactly it - allow the forum admins to set a default language for code blocks in order to override highlight.js autodetection because autodetection is undesirable if the language in the code block is not a supported one.

@julianlam to get around the dependencies issues, potentially have the text inserted after the backticks:
``` <admin set default>

with the default being blank?

Potentially, yes... the difficult part is that while the markdown parser we use has the appropriate hooks and such for mutation of inputs, I cannot easily say whether this is doable quickly or not 😄

Their plugin API is... difficult, to put it lightly. I am sure it makes sense to the author, but I am not as good a programmer as he, I think 😆