Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use json extension on mathmaps files #2403

Closed
ggrossetie opened this issue Apr 13, 2020 · 7 comments
Closed

Use json extension on mathmaps files #2403

ggrossetie opened this issue Apr 13, 2020 · 7 comments

Comments

@ggrossetie
Copy link

Is your feature request related to a problem? Please describe.

Currently, the files in the mathmaps directory are using the .js extension but they are really .json files. For instance:

sre/mathmaps/es.js

{
"es/functions/algebra.js": 
[{"locale":"es"},{"key":"deg","names":["deg"],"mappings":{"default":{"default":"grados"}},"category":"Algebra"},{"key":"det","names":["det"],"mappings":{"default":{"default":"determinante"}},"category":"Algebra"},{"key":"dim","names":["dim"],"mappings":{"default":{"default":"dimensión"}},"category":"Algebra"},{"key":"hom","names":["hom","Hom"],"mappings":{"default":{"default":"homomorfismo"}},"category":"Algebra"},{"key":"ker","names":["ker"],"mappings":{"default":{"default":"kernel"}},"category":"Algebra"},{"key":"Tr","names":["Tr","tr"],"mappings":{"default":{"default":"traza"}},"category":"Algebra"}]
,
"es/units/weight.js": 
[{"locale":"es"},{"key":"lb","names":["lb","lb."],"mappings":{"default":{"default":"libra"}},"category":"weight"},{"key":"LT","names":["LT","L.T."],"mappings":{"default":{"default":"libras imperiales"}},"category":"weight"},{"key":"oz","names":["oz","oz."],"mappings":{"default":{"default":"onza"}},"category":"weight"},{"key":"µg","names":["µg","mcg"],"mappings":{"default":{"default":"microgramo"}},"category":"weight"},{"key":"gr","names":["g","gr"],"mappings":{"default":{"default":"gramo"}},"category":"weight"},{"key":"kg","names":["kg"],"mappings":{"default":{"default":"kilogramo"}},"category":"weight"},{"key":"mg","names":["mg"],"mappings":{"default":{"default":"miligramo"}},"category":"weight"},{"key":"t","names":["t","T"],"mappings":{"default":{"default":"tonelada"}},"category":"weight"}]
}

Per say it's not really an issue but some linter/parser (more specifically the Firefox Add-ons linter: https://github.com/mozilla/addons-linter) will parse these "JavaScript" files and fail:

Code              Message                   Description                                                                                 File                                          Line   Column
JS_SYNTAX_ERROR   JavaScript syntax error   There is a JavaScript syntax error in your code; validation cannot continue on this file.   vendor/MathJax-3.0.5/sre/mathmaps/nemeth.js   2      30    
JS_SYNTAX_ERROR   JavaScript syntax error   There is a JavaScript syntax error in your code; validation cannot continue on this file.   vendor/MathJax-3.0.5/sre/mathmaps/fr.js       2      26    
JS_SYNTAX_ERROR   JavaScript syntax error   There is a JavaScript syntax error in your code; validation cannot continue on this file.   vendor/MathJax-3.0.5/sre/mathmaps/es.js       2      26    
JS_SYNTAX_ERROR   JavaScript syntax error   There is a JavaScript syntax error in your code; validation cannot continue on this file.   vendor/MathJax-3.0.5/sre/mathmaps/en.js       2      26 

In other words, if you are embedding MathJax 3.0.5 in a Firefox Add-on, you cannot publish your extension anymore.
The linter was not complaining with MathJax 3.0.1 because the structure and the files content changed.
In MathJax 3.0.1, each files contain a single Array on a single line:

sre/mathmaps/es/functions/algebra.js

[{"locale":"es"},{"key":"deg","names":["deg"],"mappings":{"default":{"default":"grados"}},"category":"Algebra"},{"key":"det","names":["det"],"mappings":{"default":{"default":"determinante"}},"category":"Algebra"},{"key":"dim","names":["dim"],"mappings":{"default":{"default":"dimensión"}},"category":"Algebra"},{"key":"hom","names":["hom","Hom"],"mappings":{"default":{"default":"homomorfismo"}},"category":"Algebra"},{"key":"ker","names":["ker"],"mappings":{"default":{"default":"kernel"}},"category":"Algebra"},{"key":"Tr","names":["Tr","tr"],"mappings":{"default":{"default":"traza"}},"category":"Algebra"}]

Describe the solution you'd like

I think the files should use the .json file extension instead of .js.

Describe alternatives you've considered

I guess we could also keep the .js file extension but declare a variable so linter and JS parser won't fail:

sre/mathmaps/es.js

var MATHMAPS_ES = {
"es/functions/algebra.js": 
[{"locale":"es"},{"key":"deg","names":["deg"],"mappings":{"default":{"default":"grados"}},"category":"Algebra"},{"key":"det","names":["det"],"mappings":{"default":{"default":"determinante"}},"category":"Algebra"},{"key":"dim","names":["dim"],"mappings":{"default":{"default":"dimensión"}},"category":"Algebra"},{"key":"hom","names":["hom","Hom"],"mappings":{"default":{"default":"homomorfismo"}},"category":"Algebra"},{"key":"ker","names":["ker"],"mappings":{"default":{"default":"kernel"}},"category":"Algebra"},{"key":"Tr","names":["Tr","tr"],"mappings":{"default":{"default":"traza"}},"category":"Algebra"}]
,
"es/units/weight.js": 
[{"locale":"es"},{"key":"lb","names":["lb","lb."],"mappings":{"default":{"default":"libra"}},"category":"weight"},{"key":"LT","names":["LT","L.T."],"mappings":{"default":{"default":"libras imperiales"}},"category":"weight"},{"key":"oz","names":["oz","oz."],"mappings":{"default":{"default":"onza"}},"category":"weight"},{"key":"µg","names":["µg","mcg"],"mappings":{"default":{"default":"microgramo"}},"category":"weight"},{"key":"gr","names":["g","gr"],"mappings":{"default":{"default":"gramo"}},"category":"weight"},{"key":"kg","names":["kg"],"mappings":{"default":{"default":"kilogramo"}},"category":"weight"},{"key":"mg","names":["mg"],"mappings":{"default":{"default":"miligramo"}},"category":"weight"},{"key":"t","names":["t","T"],"mappings":{"default":{"default":"tonelada"}},"category":"weight"}]
}
@zorkow
Copy link
Member

zorkow commented Apr 13, 2020

This is related to [SRE] (https://github.com/zorkow/speech-rule-engine) and mentioned in SRE issue 329.

The reason for the .js is that some of the CDNs MathJax uses do not serve files with .json extension. In particular, there was a longstanding issue with cdnjs.

I see that at least for cdnjs this has now been resolved and I am actually keen to go back to .json extensions (for similar reasons you mention). But we need to test with some of the other cdns that distribute MathJax and SRE, whether they'll work.

@ggrossetie
Copy link
Author

I see that at least for cdnjs this has now been resolved and I am actually keen to go back to .json extensions (for similar reasons you mention). But we need to test with some of the other cdns that distribute MathJax and SRE, whether they'll work.

Awesome, thanks for you blazing fast response ⚡

@ggrossetie
Copy link
Author

I see that at least for cdnjs this has now been resolved and I am actually keen to go back to .json extensions (for similar reasons you mention). But we need to test with some of the other cdns that distribute MathJax and SRE, whether they'll work.

@zorkow Any news on this? Do you need help to check if json files are supported by cdns? Do you have the complete list of cdns used by SRE?

@Znegl
Copy link

Znegl commented Dec 10, 2021

Any news on this bug? It seems to have been fixed by speech-rule-engine a while ago: Speech-Rule-Engine/speech-rule-engine#536

@zorkow
Copy link
Member

zorkow commented Dec 10, 2021

This is already in the latest SRE 4.0 beta release. I am hoping to get the 4.0 out before Christmas.
Either way, the next MathJax release will definitely contain the .json files.

@dpvc dpvc added this to the 3.2.1 milestone Feb 3, 2022
ggrossetie added a commit to asciidoctor/asciidoctor-browser-extension that referenced this issue Mar 12, 2022
@hubgit
Copy link

hubgit commented Mar 17, 2022

This is also a problem for webpack 5's minifier, Terser, which throws an error when it tries to parse these files as JavaScript.

@ggrossetie
Copy link
Author

Linking: mathjax/MathJax-src#745 which the pull request that integrates SRE 4.0 in MathJax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants