Merge remote-tracking branch 'fred/issue361' into develop

Resolves issue #361.
This commit is contained in:
Davide P. Cervone 2013-02-12 09:32:49 -05:00
commit fc7aa04a44

View File

@ -1,3 +1,5 @@
/* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/************************************************************* /*************************************************************
* *
* MathJax/extensions/toMathML.js * MathJax/extensions/toMathML.js
@ -106,12 +108,29 @@ MathJax.Hub.Register.LoadHook("[MathJax]/jax/element/mml/jax.js",function () {
string = String(string).split(""); string = String(string).split("");
for (var i = 0, m = string.length; i < m; i++) { for (var i = 0, m = string.length; i < m; i++) {
var n = string[i].charCodeAt(0); var n = string[i].charCodeAt(0);
if (n <= 0xD7FF || 0xE000 <= n) {
// Code points U+0000 to U+D7FF and U+E000 to U+FFFF.
// They are directly represented by n.
if (n < 0x20 || n > 0x7E) { if (n < 0x20 || n > 0x7E) {
string[i] = "&#x"+n.toString(16).toUpperCase()+";"; string[i] = "&#x"+n.toString(16).toUpperCase()+";";
} else { } else {
var c = {'&':'&amp;', '<':'&lt;', '>':'&gt;', '"':'&quot;'}[string[i]]; var c =
{'&':'&amp;', '<':'&lt;', '>':'&gt;', '"':'&quot;'}[string[i]];
if (c) {string[i] = c} if (c) {string[i] = c}
} }
} else if (i+1 < m) {
// Code points U+10000 to U+10FFFF.
// n is the lead surrogate, let's read the trail surrogate.
var trailSurrogate = string[i+1].charCodeAt(0);
var codePoint = (((n-0xD800)<<10)+(trailSurrogate-0xDC00)+0x10000);
string[i] = "&#x"+codePoint.toString(16).toUpperCase()+";";
string[i+1] = "";
i++;
} else {
// n is a lead surrogate without corresponding trail surrogate:
// remove that character.
string[i] = "";
}
} }
return string.join(""); return string.join("");
} }