www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit fc7aa04a44d0c875c5c92a6e6f7703247015df81
parent 02c0e043c6497450fb2653fd240b793f982974dd
Author: Davide P. Cervone <dpvc@union.edu>
Date:   Tue, 12 Feb 2013 09:32:49 -0500

Merge remote-tracking branch 'fred/issue361' into develop
Resolves issue #361.

Diffstat:
Munpacked/extensions/toMathML.js | 27+++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/unpacked/extensions/toMathML.js b/unpacked/extensions/toMathML.js @@ -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 @@ -106,11 +108,28 @@ MathJax.Hub.Register.LoadHook("[MathJax]/jax/element/mml/jax.js",function () { string = String(string).split(""); for (var i = 0, m = string.length; i < m; i++) { var n = string[i].charCodeAt(0); - if (n < 0x20 || n > 0x7E) { - string[i] = "&#x"+n.toString(16).toUpperCase()+";"; + 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) { + string[i] = "&#x"+n.toString(16).toUpperCase()+";"; + } else { + var c = + {'&':'&amp;', '<':'&lt;', '>':'&gt;', '"':'&quot;'}[string[i]]; + 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 { - var c = {'&':'&amp;', '<':'&lt;', '>':'&gt;', '"':'&quot;'}[string[i]]; - if (c) {string[i] = c} + // n is a lead surrogate without corresponding trail surrogate: + // remove that character. + string[i] = ""; } } return string.join("");