Make fractions take math component
This commit is contained in:
@ -2,12 +2,13 @@ import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
|
||||
import { MathRun } from "../math-run";
|
||||
import { MathDenominator } from "./math-denominator";
|
||||
|
||||
describe("MathDenominator", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathDenominator with correct root key", () => {
|
||||
const mathDenominator = new MathDenominator("2+2");
|
||||
const mathDenominator = new MathDenominator(new MathRun("2+2"));
|
||||
const tree = new Formatter().format(mathDenominator);
|
||||
expect(tree).to.deep.equal({
|
||||
"m:den": [
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
|
||||
import { MathRun } from "../math-run";
|
||||
import { MathComponent } from "../math-component";
|
||||
|
||||
export class MathDenominator extends XmlComponent {
|
||||
constructor(text: string) {
|
||||
constructor(child: MathComponent) {
|
||||
super("m:den");
|
||||
|
||||
this.root.push(new MathRun(text));
|
||||
this.root.push(child);
|
||||
}
|
||||
}
|
||||
|
@ -2,16 +2,15 @@ import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
|
||||
import { MathDenominator } from "./math-denominator";
|
||||
import { MathRun } from "../math-run";
|
||||
import { MathFraction } from "./math-fraction";
|
||||
import { MathNumerator } from "./math-numerator";
|
||||
|
||||
describe("MathFraction", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathFraction with correct root key", () => {
|
||||
const mathFraction = new MathFraction({
|
||||
numerator: new MathNumerator("2"),
|
||||
denominator: new MathDenominator("2"),
|
||||
numerator: new MathRun("2"),
|
||||
denominator: new MathRun("2"),
|
||||
});
|
||||
const tree = new Formatter().format(mathFraction);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -1,18 +1,19 @@
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
|
||||
import { MathComponent } from "../math-component";
|
||||
import { MathDenominator } from "./math-denominator";
|
||||
import { MathNumerator } from "./math-numerator";
|
||||
|
||||
export interface IMathFractionOptions {
|
||||
readonly numerator: MathNumerator;
|
||||
readonly denominator: MathDenominator;
|
||||
readonly numerator: MathComponent;
|
||||
readonly denominator: MathComponent;
|
||||
}
|
||||
|
||||
export class MathFraction extends XmlComponent {
|
||||
constructor(options: IMathFractionOptions) {
|
||||
super("m:f");
|
||||
|
||||
this.root.push(options.numerator);
|
||||
this.root.push(options.denominator);
|
||||
this.root.push(new MathNumerator(options.numerator));
|
||||
this.root.push(new MathDenominator(options.denominator));
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,13 @@ import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
|
||||
import { MathRun } from "../math-run";
|
||||
import { MathNumerator } from "./math-numerator";
|
||||
|
||||
describe("MathNumerator", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathNumerator with correct root key", () => {
|
||||
const mathNumerator = new MathNumerator("2+2");
|
||||
const mathNumerator = new MathNumerator(new MathRun("2+2"));
|
||||
const tree = new Formatter().format(mathNumerator);
|
||||
expect(tree).to.deep.equal({
|
||||
"m:num": [
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
|
||||
import { MathRun } from "../math-run";
|
||||
import { MathComponent } from "../math-component";
|
||||
|
||||
export class MathNumerator extends XmlComponent {
|
||||
constructor(text: string) {
|
||||
constructor(child: MathComponent) {
|
||||
super("m:num");
|
||||
|
||||
this.root.push(new MathRun(text));
|
||||
this.root.push(child);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user