Skip to content

Commit b2cb495

Browse files
committed
Merge branch 'mfenced' into alpha
2 parents 4a02703 + 388418d commit b2cb495

File tree

4 files changed

+130
-4
lines changed

4 files changed

+130
-4
lines changed

mathjax3-ts/core/MmlTree/MmlNodes/mfenced.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ export class MmlMfenced extends AbstractMmlNode {
4141
/*
4242
* Storage for "fake" nodes for the delimiters and separators
4343
*/
44-
protected separators: MmlNode[] = [];
45-
protected open: MmlNode = null;
46-
protected close: MmlNode = null;
44+
public separators: MmlNode[] = [];
45+
public open: MmlNode = null;
46+
public close: MmlNode = null;
4747

4848
/*
4949
* @return {string} The mfenced kind

mathjax3-ts/output/chtml/Wrappers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {CHTMLms} from './Wrappers/ms.js';
2929
import {CHTMLmspace} from './Wrappers/mspace.js';
3030
import {CHTMLmpadded} from './Wrappers/mpadded.js';
3131
import {CHTMLmrow, CHTMLinferredMrow} from './Wrappers/mrow.js';
32+
import {CHTMLmfenced} from './Wrappers/mfenced.js';
3233
import {CHTMLmfrac} from './Wrappers/mfrac.js';
3334
import {CHTMLmsqrt} from './Wrappers/msqrt.js';
3435
import {CHTMLmroot} from './Wrappers/mroot.js';
@@ -59,6 +60,7 @@ export const CHTMLWrappers: {[kind: string]: typeof CHTMLWrapper} = {
5960
[CHTMLmunder.kind]: CHTMLmunder,
6061
[CHTMLmover.kind]: CHTMLmover,
6162
[CHTMLmunderover.kind]: CHTMLmunderover,
63+
[CHTMLmfenced.kind]: CHTMLmfenced,
6264
[CHTMLmtable.kind]: CHTMLmtable,
6365
[CHTMLmtr.kind]: CHTMLmtr,
6466
[CHTMLmlabeledtr.kind]: CHTMLmlabeledtr,
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*************************************************************
2+
*
3+
* Copyright (c) 2018 The MathJax Consortium
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/**
19+
* @fileoverview Implements the CHTMLmfenced wrapper for the MmlMfenced object
20+
*
21+
* @author [email protected] (Davide Cervone)
22+
*/
23+
24+
import {CHTMLWrapper} from '../Wrapper.js';
25+
import {CHTMLWrapperFactory} from '../WrapperFactory.js';
26+
import {CHTMLinferredMrow} from './mrow.js';
27+
import {MmlMfenced} from '../../../core/MmlTree/MmlNodes/mfenced.js';
28+
import {MmlInferredMrow} from '../../../core/MmlTree/MmlNodes/mrow.js';
29+
import {MmlNode, AbstractMmlNode, AttributeList} from '../../../core/MmlTree/MmlNode.js';
30+
import {BBox} from '../BBox.js';
31+
32+
/*****************************************************************/
33+
/*
34+
* The CHTMLmfenced wrapper for the MmlMfenced object
35+
*
36+
* @template N The HTMLElement node class
37+
* @template T The Text node class
38+
* @template D The Document class
39+
*/
40+
export class CHTMLmfenced<N, T, D> extends CHTMLWrapper<N, T, D> {
41+
public static kind = MmlMfenced.prototype.kind;
42+
43+
//
44+
// An mrow to use for the layout of the mfenced
45+
//
46+
protected mrow: CHTMLinferredMrow<N, T, D> = null;
47+
48+
/*
49+
* @override
50+
* @constructor
51+
*/
52+
constructor(factory: CHTMLWrapperFactory<N, T, D>, node: MmlNode, parent: CHTMLWrapper<N, T, D> = null) {
53+
super(factory, node, parent);
54+
this.createMrow();
55+
this.addMrowChildren();
56+
}
57+
58+
/*
59+
* Creates the mrow wrapper to use for the layout
60+
*/
61+
protected createMrow() {
62+
const mmlFactory = (this.node as AbstractMmlNode).factory;
63+
const mrow = mmlFactory.create('inferredMrow');
64+
const attributes = this.node.attributes;
65+
const display = attributes.get('display') as boolean;
66+
const scriptlevel = attributes.get('scriptlevel') as number;
67+
const defaults: AttributeList = {
68+
mathsize: ['math', attributes.get('mathsize')]
69+
};
70+
mrow.setInheritedAttributes(defaults, display, scriptlevel, false);
71+
this.mrow = this.wrap(mrow) as CHTMLinferredMrow<N, T, D>;
72+
this.mrow.parent = this;
73+
}
74+
75+
/*
76+
* Populate the mrow with wrapped mo elements interleaved
77+
* with the mfenced children (the mo's are already created
78+
* in the mfenced object)
79+
*/
80+
protected addMrowChildren() {
81+
const mfenced = this.node as MmlMfenced;
82+
const mrow = this.mrow;
83+
this.addMo(mfenced.open);
84+
if (this.childNodes.length) {
85+
mrow.childNodes.push(this.childNodes[0]);
86+
}
87+
let i = 0;
88+
for (const child of this.childNodes.slice(1)) {
89+
this.addMo(mfenced.separators[i++]);
90+
mrow.childNodes.push(child);
91+
}
92+
this.addMo(mfenced.close);
93+
mrow.stretchChildren();
94+
}
95+
96+
/*
97+
* Wrap an mo element and push it onto the mrow
98+
*
99+
* @param{MmlNode} node The mo element to push on the mrow
100+
*/
101+
protected addMo(node: MmlNode) {
102+
if (!node) return;
103+
const mo = this.wrap(node);
104+
this.mrow.childNodes.push(mo);
105+
mo.parent = this.mrow;
106+
}
107+
108+
/*
109+
* @override
110+
*/
111+
public toCHTML(parent: N) {
112+
const chtml = this.standardCHTMLnode(parent);
113+
this.mrow.toCHTML(chtml);
114+
this.drawBBox();
115+
}
116+
117+
/*
118+
* @override
119+
*/
120+
public computeBBox(bbox: BBox) {
121+
bbox.updateFrom(this.mrow.getBBox());
122+
}
123+
124+
}

mathjax3-ts/output/chtml/Wrappers/mrow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class CHTMLmrow<N, T, D> extends CHTMLWrapper<N, T, D> {
8888
* Handle vertical stretching of children to match height of
8989
* other nodes in the row.
9090
*/
91-
protected stretchChildren() {
91+
public stretchChildren() {
9292
let stretchy: CHTMLWrapper<N, T, D>[] = [];
9393
//
9494
// Locate and count the stretchy children

0 commit comments

Comments
 (0)