From 21d8c09df1579b57cf89431118e468e3fec40043 Mon Sep 17 00:00:00 2001 From: Peter Krautzberger Date: Sat, 22 Apr 2017 15:25:04 +0200 Subject: [PATCH] Update fontURL, support for reconfiguration Fixes #323 --- README.md | 2 +- lib/main.js | 10 ++++++++-- test/base-config-fonturl.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 test/base-config-fonturl.js diff --git a/README.md b/README.md index d35b375a..fda4b323 100644 --- a/README.md +++ b/README.md @@ -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. } ``` diff --git a/lib/main.js b/lib/main.js index c54b4856..a614ba6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -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 @@ -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} } diff --git a/test/base-config-fonturl.js b/test/base-config-fonturl.js new file mode 100644 index 00000000..55d7212f --- /dev/null +++ b/test/base-config-fonturl.js @@ -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'); + }); +}); \ No newline at end of file