fix: Prevent global group from adversely affecting color. (#2703)

Co-authored-by: ylemkimon <y@ylem.kim>
This commit is contained in:
Ron Kok
2020-12-29 11:52:41 -08:00
committed by GitHub
parent 157c779f1b
commit cd9ee27ac6
2 changed files with 7 additions and 0 deletions

View File

@@ -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")) {

View File

@@ -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({});