mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-06 11:48:41 +00:00
fix: Prevent global group from adversely affecting color. (#2703)
Co-authored-by: ylemkimon <y@ylem.kim>
This commit is contained in:
@@ -18,10 +18,16 @@ const parseTree = function(toParse: string, settings: Settings): AnyParseNode[]
|
|||||||
throw new TypeError('KaTeX can only parse string typed expression');
|
throw new TypeError('KaTeX can only parse string typed expression');
|
||||||
}
|
}
|
||||||
const parser = new Parser(toParse, settings);
|
const parser = new Parser(toParse, settings);
|
||||||
|
|
||||||
// Blank out any \df@tag to avoid spurious "Duplicate \tag" errors
|
// Blank out any \df@tag to avoid spurious "Duplicate \tag" errors
|
||||||
delete parser.gullet.macros.current["\\df@tag"];
|
delete parser.gullet.macros.current["\\df@tag"];
|
||||||
|
|
||||||
let tree = parser.parse();
|
let tree = parser.parse();
|
||||||
|
|
||||||
|
// Prevent a color definition from persisting between calls to katex.render().
|
||||||
|
delete parser.gullet.macros.current["\\current@color"];
|
||||||
|
delete parser.gullet.macros.current["\\color"];
|
||||||
|
|
||||||
// If the input used \tag, it will set the \df@tag macro to the tag.
|
// If the input used \tag, it will set the \df@tag macro to the tag.
|
||||||
// In this case, we separately parse the tag and wrap the tree.
|
// In this case, we separately parse the tag and wrap the tree.
|
||||||
if (parser.gullet.macros.get("\\df@tag")) {
|
if (parser.gullet.macros.get("\\df@tag")) {
|
||||||
|
@@ -869,6 +869,7 @@ describe("A color parser", function() {
|
|||||||
const macros = {};
|
const macros = {};
|
||||||
expect(oldColorExpression).toParseLike(r`\textcolor{#fA6}{x}y`, {
|
expect(oldColorExpression).toParseLike(r`\textcolor{#fA6}{x}y`, {
|
||||||
colorIsTextColor: true,
|
colorIsTextColor: true,
|
||||||
|
globalGroup: true,
|
||||||
macros: macros,
|
macros: macros,
|
||||||
});
|
});
|
||||||
expect(macros).toEqual({});
|
expect(macros).toEqual({});
|
||||||
|
Reference in New Issue
Block a user