Make fractions take math component
This commit is contained in:
@ -6,10 +6,8 @@ import {
|
||||
Math,
|
||||
MathAngledBrackets,
|
||||
MathCurlyBrackets,
|
||||
MathDenominator,
|
||||
MathFraction,
|
||||
MathFunction,
|
||||
MathNumerator,
|
||||
MathPreSubSuperScript,
|
||||
MathRadical,
|
||||
MathRoundBrackets,
|
||||
@ -35,8 +33,8 @@ doc.addSection({
|
||||
children: [
|
||||
new MathRun("2+2"),
|
||||
new MathFraction({
|
||||
numerator: new MathNumerator("hi"),
|
||||
denominator: new MathDenominator("2"),
|
||||
numerator: new MathRun("hi"),
|
||||
denominator: new MathRun("2"),
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@ -142,8 +140,8 @@ doc.addSection({
|
||||
children: [
|
||||
new MathSubScript({
|
||||
child: new MathFraction({
|
||||
numerator: new MathNumerator("1"),
|
||||
denominator: new MathDenominator("2"),
|
||||
numerator: new MathRun("1"),
|
||||
denominator: new MathRun("2"),
|
||||
}),
|
||||
subScript: new MathRun("4"),
|
||||
}),
|
||||
@ -158,8 +156,8 @@ doc.addSection({
|
||||
new MathSubScript({
|
||||
child: new MathRadical({
|
||||
child: new MathFraction({
|
||||
numerator: new MathNumerator("1"),
|
||||
denominator: new MathDenominator("2"),
|
||||
numerator: new MathRun("1"),
|
||||
denominator: new MathRun("2"),
|
||||
}),
|
||||
degree: new MathRun("4"),
|
||||
}),
|
||||
@ -207,26 +205,26 @@ doc.addSection({
|
||||
children: [
|
||||
new MathRoundBrackets({
|
||||
child: new MathFraction({
|
||||
numerator: new MathNumerator("1"),
|
||||
denominator: new MathDenominator("2"),
|
||||
numerator: new MathRun("1"),
|
||||
denominator: new MathRun("2"),
|
||||
}),
|
||||
}),
|
||||
new MathSquareBrackets({
|
||||
child: new MathFraction({
|
||||
numerator: new MathNumerator("1"),
|
||||
denominator: new MathDenominator("2"),
|
||||
numerator: new MathRun("1"),
|
||||
denominator: new MathRun("2"),
|
||||
}),
|
||||
}),
|
||||
new MathCurlyBrackets({
|
||||
child: new MathFraction({
|
||||
numerator: new MathNumerator("1"),
|
||||
denominator: new MathDenominator("2"),
|
||||
numerator: new MathRun("1"),
|
||||
denominator: new MathRun("2"),
|
||||
}),
|
||||
}),
|
||||
new MathAngledBrackets({
|
||||
child: new MathFraction({
|
||||
numerator: new MathNumerator("1"),
|
||||
denominator: new MathDenominator("2"),
|
||||
numerator: new MathRun("1"),
|
||||
denominator: new MathRun("2"),
|
||||
}),
|
||||
}),
|
||||
],
|
||||
@ -238,14 +236,10 @@ doc.addSection({
|
||||
new Math({
|
||||
children: [
|
||||
new MathFraction({
|
||||
numerator: new Math({
|
||||
children: [
|
||||
new MathRadical({
|
||||
numerator: new MathRadical({
|
||||
child: new MathRun("4"),
|
||||
}),
|
||||
],
|
||||
}),
|
||||
demoninator: new MathRun("2a"),
|
||||
denominator: new MathRun("2a"),
|
||||
}),
|
||||
],
|
||||
}),
|
||||
|
@ -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