mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-10 05:28:41 +00:00
fix: \char support for >16-bit Unicode characters (#3006)
* fix: \char support for >16-bit Unicode characters `String.fromCharCode` only supports Unicode characters up to 16-bit. `String.fromCodePoint` from ECMAScript 2015 supports all Unicode code points. Unfortunately, IE doesn't support the latter, so use former as fallback. Fixes #3004 Co-authored-by: ylemkimon <y@ylem.kim>
This commit is contained in:
@@ -21,14 +21,25 @@ defineFunction({
|
||||
const node = assertNodeType(group[i], "textord");
|
||||
number += node.text;
|
||||
}
|
||||
const code = parseInt(number);
|
||||
let code = parseInt(number);
|
||||
let text;
|
||||
if (isNaN(code)) {
|
||||
throw new ParseError(`\\@char has non-numeric argument ${number}`);
|
||||
// If we drop IE support, the following code could be replaced with
|
||||
// text = String.fromCodePoint(code)
|
||||
} else if (code < 0 || code >= 0x10ffff) {
|
||||
throw new ParseError(`\\@char with invalid code point ${number}`);
|
||||
} else if (code <= 0xffff) {
|
||||
text = String.fromCharCode(code);
|
||||
} else { // Astral code point; split into surrogate halves
|
||||
code -= 0x10000;
|
||||
text = String.fromCharCode((code >> 10) + 0xd800,
|
||||
(code & 0x3ff) + 0xdc00);
|
||||
}
|
||||
return {
|
||||
type: "textord",
|
||||
mode: parser.mode,
|
||||
text: String.fromCharCode(code),
|
||||
text: text,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
Reference in New Issue
Block a user