rtfpessoa/diff2html

How to highlight with a custom language and extension mapping

quentin opened this issue · 1 comments

Hi,
I have a custom language (say foolang) registered in the hljs instance, is it possible to highlight a language that is not listed there:

const languagesToExt: { [_: string]: string } = {

It is properly detected in the language variable (because the extension of the filename in the diff is .foolang):

const language = file.getAttribute('data-lang');
const hljsLanguage = language ? getLanguage(language) : 'plaintext';

But this code discards it for 'plaintext' since it is not listed in languagesToExt:

export function getLanguage(fileExtension: string): string {
return languagesToExt[fileExtension] ?? 'plaintext';
}

It would be convenient to be able to register custom language/extension mappings.

👋 Thanks for the contribution. Left a comment in the PR.