Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Commit

Permalink
[main] refactor normalizing scripts (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkra committed Apr 28, 2017
1 parent 5fba358 commit 2478b91
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
29 changes: 11 additions & 18 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ exports.mjpage = function(htmlstring, configOptions, typesetOptions, callback) {
const window = doc.defaultView;
const document = window.document;

//rewrite custom scripts types from core MathJax
const rewriteScripts = function(oldType, newType){
const scripts = document.querySelectorAll('script[type="' + oldType + '"]');
for (let script of scripts) script.setAttribute('type', newType);
}
rewriteScripts('math/tex','math/inline-TeX');
rewriteScripts('math/tex; mode=display','math/TeX');
rewriteScripts('math/asciimath','math/asciiMath');

// configure mathjax-node
mathjax.config(config);

Expand Down Expand Up @@ -113,23 +122,7 @@ exports.mjpage = function(htmlstring, configOptions, typesetOptions, callback) {
window.ascii.config.doc = document;
window.ascii.PreProcess();
}
//normalize type strings
const allScripts = document.querySelectorAll('script[type^="math/"]');
for (let i = 0; i < allScripts.length; i++) {
const script = allScripts[i];
let format = script.getAttribute('type');
if (format === "math/tex") {
format = "math/inline-TeX";
} else if (format === 'math/tex; mode=display') {
format = "math/TeX";
} else if (format === 'math/asciimath') {
format = 'math/AsciiMath'
}
else {
continue;
}
script.setAttribute('type', format);
}

const scripts = document.querySelectorAll(`
script[type="math/TeX"],
script[type="math/inline-TeX"],
Expand Down Expand Up @@ -234,7 +227,7 @@ exports.mjpage = function(htmlstring, configOptions, typesetOptions, callback) {
border: 0;
margin: 0
}
.mjpage__block {
text-align: center;
margin: 1em 0em;
Expand Down
2 changes: 1 addition & 1 deletion test/script-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ tape('Custom script types are processed correctly', function(t) {
}, function(output) {
const window = jsdom(output).defaultView;
const expected = window.document.querySelector('.mjpage');
t.notOk(expected, 'Case and space insensitivity');
t.notOk(expected, 'Other scripts are ignored');
});

});

0 comments on commit 2478b91

Please sign in to comment.