rtfpessoa / diff2html

Pretty diff to html javascript library (diff2html)
https://diff2html.xyz
MIT License
2.8k stars 273 forks source link

How to highlight with a custom language and extension mapping #437

Closed quentin closed 1 year ago

quentin commented 2 years ago

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: https://github.com/rtfpessoa/diff2html/blob/e5c813949fcbb9a0b96ce528f49539d63cbdcf40/src/ui/js/highlight.js-helpers.ts#L164

It is properly detected in the language variable (because the extension of the filename in the diff is .foolang): https://github.com/rtfpessoa/diff2html/blob/e5c813949fcbb9a0b96ce528f49539d63cbdcf40/src/ui/js/diff2html-ui-base.ts#L144-L145

But this code discards it for 'plaintext' since it is not listed in languagesToExt: https://github.com/rtfpessoa/diff2html/blob/e5c813949fcbb9a0b96ce528f49539d63cbdcf40/src/ui/js/highlight.js-helpers.ts#L653-L655

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

rtfpessoa commented 2 years ago

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