-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
StandardBranchingNode.ts
30 lines (27 loc) · 1.1 KB
/
StandardBranchingNode.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { Placeholder } from '../../Placeholder/Placeholder';
import { LatexConfiguration } from '../../../LatexConfiguration';
import { BranchingNode } from '../Base/BranchingNode';
import { KeyboardMemory } from '../../../KeyboardEngine/KeyboardMemory';
export class StandardBranchingNode extends BranchingNode {
private readonly before: string;
private readonly then: string;
private readonly rest: string[];
constructor(before: string, then: string, ...rest: string[]) {
const placeholderCount = rest.length + 1;
const placeholders = new Array<Placeholder>();
for (let i = 0; i < placeholderCount; i++) {
placeholders.push(new Placeholder());
}
super(placeholders);
this.before = before;
this.then = then;
this.rest = rest;
}
getLatexPart(k: KeyboardMemory, latexConfiguration: LatexConfiguration): string {
let latex = this.before + this.placeholders[0].getLatex(k, latexConfiguration) + this.then;
for (let i = 0; i < this.rest.length; i++) {
latex += this.placeholders[i + 1].getLatex(k, latexConfiguration) + this.rest[i];
}
return latex;
}
}