Make fractions take math component
This commit is contained in:
@ -6,10 +6,8 @@ import {
|
|||||||
Math,
|
Math,
|
||||||
MathAngledBrackets,
|
MathAngledBrackets,
|
||||||
MathCurlyBrackets,
|
MathCurlyBrackets,
|
||||||
MathDenominator,
|
|
||||||
MathFraction,
|
MathFraction,
|
||||||
MathFunction,
|
MathFunction,
|
||||||
MathNumerator,
|
|
||||||
MathPreSubSuperScript,
|
MathPreSubSuperScript,
|
||||||
MathRadical,
|
MathRadical,
|
||||||
MathRoundBrackets,
|
MathRoundBrackets,
|
||||||
@ -35,8 +33,8 @@ doc.addSection({
|
|||||||
children: [
|
children: [
|
||||||
new MathRun("2+2"),
|
new MathRun("2+2"),
|
||||||
new MathFraction({
|
new MathFraction({
|
||||||
numerator: new MathNumerator("hi"),
|
numerator: new MathRun("hi"),
|
||||||
denominator: new MathDenominator("2"),
|
denominator: new MathRun("2"),
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
@ -142,8 +140,8 @@ doc.addSection({
|
|||||||
children: [
|
children: [
|
||||||
new MathSubScript({
|
new MathSubScript({
|
||||||
child: new MathFraction({
|
child: new MathFraction({
|
||||||
numerator: new MathNumerator("1"),
|
numerator: new MathRun("1"),
|
||||||
denominator: new MathDenominator("2"),
|
denominator: new MathRun("2"),
|
||||||
}),
|
}),
|
||||||
subScript: new MathRun("4"),
|
subScript: new MathRun("4"),
|
||||||
}),
|
}),
|
||||||
@ -158,8 +156,8 @@ doc.addSection({
|
|||||||
new MathSubScript({
|
new MathSubScript({
|
||||||
child: new MathRadical({
|
child: new MathRadical({
|
||||||
child: new MathFraction({
|
child: new MathFraction({
|
||||||
numerator: new MathNumerator("1"),
|
numerator: new MathRun("1"),
|
||||||
denominator: new MathDenominator("2"),
|
denominator: new MathRun("2"),
|
||||||
}),
|
}),
|
||||||
degree: new MathRun("4"),
|
degree: new MathRun("4"),
|
||||||
}),
|
}),
|
||||||
@ -207,26 +205,26 @@ doc.addSection({
|
|||||||
children: [
|
children: [
|
||||||
new MathRoundBrackets({
|
new MathRoundBrackets({
|
||||||
child: new MathFraction({
|
child: new MathFraction({
|
||||||
numerator: new MathNumerator("1"),
|
numerator: new MathRun("1"),
|
||||||
denominator: new MathDenominator("2"),
|
denominator: new MathRun("2"),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
new MathSquareBrackets({
|
new MathSquareBrackets({
|
||||||
child: new MathFraction({
|
child: new MathFraction({
|
||||||
numerator: new MathNumerator("1"),
|
numerator: new MathRun("1"),
|
||||||
denominator: new MathDenominator("2"),
|
denominator: new MathRun("2"),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
new MathCurlyBrackets({
|
new MathCurlyBrackets({
|
||||||
child: new MathFraction({
|
child: new MathFraction({
|
||||||
numerator: new MathNumerator("1"),
|
numerator: new MathRun("1"),
|
||||||
denominator: new MathDenominator("2"),
|
denominator: new MathRun("2"),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
new MathAngledBrackets({
|
new MathAngledBrackets({
|
||||||
child: new MathFraction({
|
child: new MathFraction({
|
||||||
numerator: new MathNumerator("1"),
|
numerator: new MathRun("1"),
|
||||||
denominator: new MathDenominator("2"),
|
denominator: new MathRun("2"),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@ -238,14 +236,10 @@ doc.addSection({
|
|||||||
new Math({
|
new Math({
|
||||||
children: [
|
children: [
|
||||||
new MathFraction({
|
new MathFraction({
|
||||||
numerator: new Math({
|
numerator: new MathRadical({
|
||||||
children: [
|
child: new MathRun("4"),
|
||||||
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 { Formatter } from "export/formatter";
|
||||||
|
|
||||||
|
import { MathRun } from "../math-run";
|
||||||
import { MathDenominator } from "./math-denominator";
|
import { MathDenominator } from "./math-denominator";
|
||||||
|
|
||||||
describe("MathDenominator", () => {
|
describe("MathDenominator", () => {
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a MathDenominator with correct root key", () => {
|
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);
|
const tree = new Formatter().format(mathDenominator);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"m:den": [
|
"m:den": [
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { XmlComponent } from "file/xml-components";
|
import { XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
import { MathRun } from "../math-run";
|
import { MathComponent } from "../math-component";
|
||||||
|
|
||||||
export class MathDenominator extends XmlComponent {
|
export class MathDenominator extends XmlComponent {
|
||||||
constructor(text: string) {
|
constructor(child: MathComponent) {
|
||||||
super("m:den");
|
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 { Formatter } from "export/formatter";
|
||||||
|
|
||||||
import { MathDenominator } from "./math-denominator";
|
import { MathRun } from "../math-run";
|
||||||
import { MathFraction } from "./math-fraction";
|
import { MathFraction } from "./math-fraction";
|
||||||
import { MathNumerator } from "./math-numerator";
|
|
||||||
|
|
||||||
describe("MathFraction", () => {
|
describe("MathFraction", () => {
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a MathFraction with correct root key", () => {
|
it("should create a MathFraction with correct root key", () => {
|
||||||
const mathFraction = new MathFraction({
|
const mathFraction = new MathFraction({
|
||||||
numerator: new MathNumerator("2"),
|
numerator: new MathRun("2"),
|
||||||
denominator: new MathDenominator("2"),
|
denominator: new MathRun("2"),
|
||||||
});
|
});
|
||||||
const tree = new Formatter().format(mathFraction);
|
const tree = new Formatter().format(mathFraction);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
import { XmlComponent } from "file/xml-components";
|
import { XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
|
import { MathComponent } from "../math-component";
|
||||||
import { MathDenominator } from "./math-denominator";
|
import { MathDenominator } from "./math-denominator";
|
||||||
import { MathNumerator } from "./math-numerator";
|
import { MathNumerator } from "./math-numerator";
|
||||||
|
|
||||||
export interface IMathFractionOptions {
|
export interface IMathFractionOptions {
|
||||||
readonly numerator: MathNumerator;
|
readonly numerator: MathComponent;
|
||||||
readonly denominator: MathDenominator;
|
readonly denominator: MathComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MathFraction extends XmlComponent {
|
export class MathFraction extends XmlComponent {
|
||||||
constructor(options: IMathFractionOptions) {
|
constructor(options: IMathFractionOptions) {
|
||||||
super("m:f");
|
super("m:f");
|
||||||
|
|
||||||
this.root.push(options.numerator);
|
this.root.push(new MathNumerator(options.numerator));
|
||||||
this.root.push(options.denominator);
|
this.root.push(new MathDenominator(options.denominator));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,13 @@ import { expect } from "chai";
|
|||||||
|
|
||||||
import { Formatter } from "export/formatter";
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
|
import { MathRun } from "../math-run";
|
||||||
import { MathNumerator } from "./math-numerator";
|
import { MathNumerator } from "./math-numerator";
|
||||||
|
|
||||||
describe("MathNumerator", () => {
|
describe("MathNumerator", () => {
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create a MathNumerator with correct root key", () => {
|
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);
|
const tree = new Formatter().format(mathNumerator);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"m:num": [
|
"m:num": [
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { XmlComponent } from "file/xml-components";
|
import { XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
import { MathRun } from "../math-run";
|
import { MathComponent } from "../math-component";
|
||||||
|
|
||||||
export class MathNumerator extends XmlComponent {
|
export class MathNumerator extends XmlComponent {
|
||||||
constructor(text: string) {
|
constructor(child: MathComponent) {
|
||||||
super("m:num");
|
super("m:num");
|
||||||
|
|
||||||
this.root.push(new MathRun(text));
|
this.root.push(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user