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

Update fontURL, support for reconfiguration #324

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ The `config` method is used to set _global_ configuration options. Its default o
displayErrors: true, // determines whether error messages are shown on the console
undefinedCharError: false, // determines whether "unknown characters" (i.e., no glyph in the configured fonts) are saved in the error array
extensions: '', // a convenience option to add MathJax extensions
fontURL: 'https://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS', // for webfont urls in the CSS for HTML output
fontURL: 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/fonts/HTML-CSS', // for webfont urls in the CSS for HTML output
MathJax: { } // standard MathJax configuration options, see https://docs.mathjax.org for more detail.
}
```
Expand Down
10 changes: 8 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var displayMessages = false; // don't log Message.Set() calls
var displayErrors = true; // show error messages on the console
var undefinedChar = false; // unknown characters are not saved in the error array
var extensions = ''; // no additional extensions used
var fontURL = 'https://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS'; // location of web fonts for CHTML
var fontURL = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/fonts/HTML-CSS'; // location of web fonts for CHTML

var defaults = {
ex: 6, // ex-size in pixels
Expand Down Expand Up @@ -865,6 +865,12 @@ exports.config = function (config) {
if (config.displayErrors != null) {displayErrors = config.displayErrors}
if (config.undefinedCharError != null) {undefinedChar = config.undefinedCharError}
if (config.extensions != null) {extensions = config.extensions}
if (config.fontURL != null) {fontURL = config.fontURL}
if (config.fontURL != null) {
if(CHTMLSTYLES && fontURL !== config.fontURL) {
var expression = new RegExp(fontURL, "g");
CHTMLSTYLES = CHTMLSTYLES.replace(expression,config.fontURL)
}
fontURL = config.fontURL;
}
if (config.MathJax) {MathJaxConfig = config.MathJax}
}
30 changes: 30 additions & 0 deletions test/base-config-fonturl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var tape = require('tape');
var mjAPI = require("../lib/main.js");

tape('basic configuration: check fontURL', function (t) {
t.plan(2);

var tex = 'a';
mjAPI.typeset({
math: tex,
format: "TeX",
css: true
}, function (result, data) {
t.ok(result.css.indexOf('https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/fonts/HTML-CSS') > -1, 'Default fontURL');
});
// reconfigure
mjAPI.typeset({
math: ''
}, function(){
mjAPI.config({
fontURL: 'https://example.com'
});
})
mjAPI.typeset({
math: tex,
format: "TeX",
css: true,
}, function (result, data) {
t.ok(result.css.indexOf('https://example.com') > -1, 'Configuring fontURL');
});
});