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 #535

Closed
ggrossetie opened this issue Jun 19, 2021 · 0 comments · Fixed by #536
Closed

Use json extension on mathmaps files #535

ggrossetie opened this issue Jun 19, 2021 · 0 comments · Fixed by #536

Comments

@ggrossetie
Copy link
Contributor

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"}]
}

Original issue: mathjax/MathJax#2403

ggrossetie added a commit to ggrossetie/speech-rule-engine that referenced this issue Jun 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant