Page MenuHomeSoftware Heritage

assets/highlightjs: Add new languages to highlight and fix some issues
ClosedPublic

Authored by anlambert on Jan 25 2022, 3:23 PM.

Details

Summary

Add support for new programming languages to highlight in the webapp
by integrating highlight.js language plugins in the highlightjs chunk
generated by webpack.

Fix issue in Python code that was preventing to map a mimetype to a
language through its aliases.

The following new languages will be highlighted once these changes deployed:

Diff Detail

Repository
rDWAPPS Web applications
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

assets/config/webpack-plugins/generate-weblabels-webpack-plugin/index.js
154–163

This change lives in a separate commit.

Build has FAILED

Patch application report for D7032 (id=25496)

Rebasing onto 1f6bf0c1f5...

Current branch diff-target is up to date.
Changes applied before test
commit c7e7d5c76918040cbefe56e5c566f5ad6537811e
Author: Antoine Lambert <anlambert@softwareheritage.org>
Date:   Tue Jan 25 14:36:30 2022 +0100

    assets/highlightjs: Add new languages to highlight and fix some issues
    
    Add support for new programming languages to highlight in the webapp
    by integrating highlight.js language plugins in the highlightjs chunk
    generated by webpack.
    
    Fix issue in Python code that was preventing to map a mimetype to a
    language through its aliases.

commit bce990970824d00ec818fdfb677df54652976a3b
Author: Antoine Lambert <anlambert@softwareheritage.org>
Date:   Tue Jan 25 14:37:55 2022 +0100

    webpack/weblabels-plugin: Read package.json file only when required
    
    Some module folders do not have package.json file in it but licenses can
    still be overridden using the licenseOverride option of the plugin.
    
    Previously, package.json file was attempted to be read regardless of
    possible license override, which was causing error.

Link to build: https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/1301/
See console output for more information: https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/1301/console

Harbormaster returned this revision to the author for changes because remote builds failed.Jan 25 2022, 3:40 PM
Harbormaster failed remote builds in B26328: Diff 25496!

Build is green

Patch application report for D7032 (id=25506)

Rebasing onto 1f6bf0c1f5...

Current branch diff-target is up to date.
Changes applied before test
commit 7ea3aab33ed8f7c9a748f6dfa85a87645aa6079e
Author: Antoine Lambert <anlambert@softwareheritage.org>
Date:   Tue Jan 25 14:36:30 2022 +0100

    assets/highlightjs: Add new languages to highlight and fix some issues
    
    Add support for new programming languages to highlight in the webapp
    by integrating highlight.js language plugins in the highlightjs chunk
    generated by webpack.
    
    Fix issue in Python code that was preventing to map a mimetype to a
    language through its aliases.

commit bce990970824d00ec818fdfb677df54652976a3b
Author: Antoine Lambert <anlambert@softwareheritage.org>
Date:   Tue Jan 25 14:37:55 2022 +0100

    webpack/weblabels-plugin: Read package.json file only when required
    
    Some module folders do not have package.json file in it but licenses can
    still be overridden using the licenseOverride option of the plugin.
    
    Previously, package.json file was attempted to be read regardless of
    possible license override, which was causing error.

See https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/1303/ for more details.

ardumont added a subscriber: ardumont.

lgtm

couple of question/suggestion inline.

assets/config/webpack-plugins/dump-highlightjs-languages-data-plugin.js
50 ↗(On Diff #25506)

can't we do a for loop or something? (and another for the registerLanguage stanza).

swh/web/common/highlightjs.py
32 ↗(On Diff #25506)

why the pop though? I see some mapping about it later on.

This revision is now accepted and ready to land.Jan 26 2022, 9:31 AM
assets/config/webpack-plugins/dump-highlightjs-languages-data-plugin.js
50 ↗(On Diff #25506)

Maybe here with the require syntax but not in the highlightjs.js file with the import syntax.
So I will keep it that way.

swh/web/common/highlightjs.py
32 ↗(On Diff #25506)

Because it clashes with the plaintext language.

Nevertheless, robots.txt files will be correctly highlighted thanks to the _filename_to_hljs_language dict.