mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-05 19:28:39 +00:00
Fix MathML output for ' and large operators with limits (#788)
Summary: (@kevinbarabash) This diff extracts MathML builder tests out into a separate file and updates them to use jest snapshot testing. It updates the output of prime ' from using identifier nodes <mi> to operator nodes <mo>. It also updates large operators with limits to use munderover instead of msupsub. I added an option to remove unnecessary mrows to buildGroup. Right now it's only used for by groupTypes.supsub. I'll see if it can be used elsewhere (everywhere?) in a follow up PR. Test Plan: - make test w/o errors - verify mathml snapshots contain the desired markup
This commit is contained in:
committed by
Erik Demaine
parent
e00738d16f
commit
fafaf85f96
52
test/mathml-spec.js
Normal file
52
test/mathml-spec.js
Normal file
@@ -0,0 +1,52 @@
|
||||
/* global expect: false */
|
||||
/* global it: false */
|
||||
/* global describe: false */
|
||||
|
||||
import buildMathML from "../src/buildMathML";
|
||||
import parseTree from "../src/parseTree";
|
||||
import Options from "../src/Options";
|
||||
import Settings from "../src/Settings";
|
||||
import Style from "../src/Style";
|
||||
|
||||
const defaultSettings = new Settings({});
|
||||
|
||||
const getMathML = function(expr, settings) {
|
||||
const usedSettings = settings ? settings : defaultSettings;
|
||||
|
||||
let startStyle = Style.TEXT;
|
||||
if (usedSettings.displayMode) {
|
||||
startStyle = Style.DISPLAY;
|
||||
}
|
||||
|
||||
// Setup the default options
|
||||
const options = new Options({
|
||||
style: startStyle,
|
||||
});
|
||||
|
||||
const built = buildMathML(parseTree(expr, usedSettings), expr, options);
|
||||
|
||||
// Strip off the surrounding <span>
|
||||
return built.children[0].toMarkup();
|
||||
};
|
||||
|
||||
describe("A MathML builder", function() {
|
||||
it('should generate the right types of nodes', () => {
|
||||
expect(getMathML("\\sin{x}+1\\;\\text{a}")).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should make prime operators into <mo> nodes', () => {
|
||||
expect(getMathML("f'")).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should generate <mphantom> nodes for \\phantom', () => {
|
||||
expect(getMathML("\\phantom{x}")).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should use <munderover> for large operators', () => {
|
||||
expect(getMathML("\\displaystyle\\sum_a^b")).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should use <msupsub> for regular operators', () => {
|
||||
expect(getMathML("\\textstyle\\sum_a^b")).toMatchSnapshot();
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user