Skip to content

Enable to manually select the programming language to highlight

When browsing source code using the Software Heritage web application, it is highlighted client-side using the highlight.js library.

The programming language to highlight is selected based on heuristics using the filename or the file mime type.

While the selected programming language is most of the time the correct one (notably !146 (closed) improves that detection), it exists cases where the wrong one is picked, resulting in an invalid code highlighting (for instance when a file extension is common to multiple languages).

Also, when no filename information is given (for instance when browsing a source file through its cryptographic hash), only the mime type can be used for selecting a programming language. This often results in no language being selected as there is not enough information to find the correct one (see for instance this go source file).

We should give to users the possibility to manually select the programming language to highlight in case it has been badly detected by our heuristics. One possibility would be to add a combo box in the right part of a source file panel header (currently missing when browsing a content by hash only) filled with all languages supported by the highlight.js library. The user can then select the language in that combo box and the code highlighting needs to be updated accordingly. A new query parameter language could also be added to the content views of swh-web/browse in order for the language to be automatically set when the corresponding page is loaded.


Migrated from T1909 (view on Phabricator)

Edited by Phabricator Migration user
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information