Skip to content

Commit 712294c

Browse files
authored
Merge pull request #1362 from mathjax/issue3443
Fix problem with Styles handling of margin. (mathjax/MathJax#3443)
2 parents 49d2acf + 1af7208 commit 712294c

File tree

3 files changed

+109
-2
lines changed

3 files changed

+109
-2
lines changed

testsuite/tests/util/Styles.test.ts

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,69 @@ describe('CssStyles object', () => {
8282
'padding-right': '0',
8383
'padding-top': '0'
8484
}, 'padding: 0;');
85+
cssTest('padding-left: 2px; padding: 0', {
86+
'padding': '0',
87+
'padding-bottom': '0',
88+
'padding-left': '0',
89+
'padding-right': '0',
90+
'padding-top': '0'
91+
}, 'padding: 0;');
8592
cssTest('padding:', {}, '');
8693
});
8794

95+
test('margin', () => {
96+
cssTest('margin-left: 2px; margin: 0', {
97+
'margin': '0',
98+
'margin-bottom': '0',
99+
'margin-left': '0',
100+
'margin-right': '0',
101+
'margin-top': '0'
102+
}, 'margin: 0;');
103+
cssTest('margin: 3px', {
104+
'margin': '3px',
105+
'margin-bottom': '3px',
106+
'margin-left': '3px',
107+
'margin-right': '3px',
108+
'margin-top': '3px'
109+
});
110+
cssTest('margin: 3px; margin-right: 1px', {
111+
'margin': '3px 1px 3px 3px',
112+
'margin-bottom': '3px',
113+
'margin-left': '3px',
114+
'margin-right': '1px',
115+
'margin-top': '3px'
116+
}, 'margin: 3px 1px 3px 3px;');
117+
cssTest('margin-top: 0; margin-right: 1px; margin-bottom: 0; margin-left: 1px', {
118+
'margin': '0 1px',
119+
'margin-bottom': '0',
120+
'margin-left': '1px',
121+
'margin-right': '1px',
122+
'margin-top': '0'
123+
}, 'margin: 0 1px;');
124+
cssTest('margin-top: 0; margin-right: 1px; margin-bottom: 2px; margin-left: 1px', {
125+
'margin': '0 1px 2px',
126+
'margin-bottom': '2px',
127+
'margin-left': '1px',
128+
'margin-right': '1px',
129+
'margin-top': '0'
130+
}, 'margin: 0 1px 2px;');
131+
cssTest('margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0', {
132+
'margin': '0',
133+
'margin-bottom': '0',
134+
'margin-left': '0',
135+
'margin-right': '0',
136+
'margin-top': '0'
137+
}, 'margin: 0;');
138+
cssTest('margin-left: 2px; margin: 0', {
139+
'margin': '0',
140+
'margin-bottom': '0',
141+
'margin-left': '0',
142+
'margin-right': '0',
143+
'margin-top': '0'
144+
}, 'margin: 0;');
145+
cssTest('margin:', {}, '');
146+
}),
147+
88148
test('border', () => {
89149
cssTest('border: 3px solid red', {
90150
'border': '3px solid red',
@@ -255,6 +315,31 @@ describe('CssStyles object', () => {
255315
'background': 'red',
256316
'background-clip': 'none',
257317
});
318+
cssTest(' border-top: inset blue 2px; border: 3px solid red', {
319+
'border': '3px solid red',
320+
'border-top': '3px solid red',
321+
'border-top-color': 'red',
322+
'border-top-style': 'solid',
323+
'border-top-width': '3px',
324+
'border-right': '3px solid red',
325+
'border-right-color': 'red',
326+
'border-right-style': 'solid',
327+
'border-right-width': '3px',
328+
'border-bottom': '3px solid red',
329+
'border-bottom-color': 'red',
330+
'border-bottom-style': 'solid',
331+
'border-bottom-width': '3px',
332+
'border-left': '3px solid red',
333+
'border-left-color': 'red',
334+
'border-left-style': 'solid',
335+
'border-left-width': '3px',
336+
}, 'border: 3px solid red;');
337+
cssTest('border-top-color: blue; border-top: 3px solid red', {
338+
'border-top': '3px solid red',
339+
'border-top-color': 'red',
340+
'border-top-style': 'solid',
341+
'border-top-width': '3px',
342+
}, 'border-top: 3px solid red;');
258343
});
259344

260345
test('font', () => {
@@ -356,4 +441,16 @@ describe('CssStyles object', () => {
356441
expect(styles.get('border')).toBe('');
357442
});
358443

444+
test('set()', () => {
445+
const styles = new Styles('padding-left: 2px');
446+
styles.set('padding-left', '3px');
447+
expect(styles.get('padding-left')).toBe('3px');
448+
expect(styles.get('padding')).toBe('');
449+
expect(styles.cssText).toBe('padding-left: 3px;');
450+
styles.set('padding', '');
451+
expect(styles.get('padding-left')).toBe('');
452+
expect(styles.get('padding')).toBe('');
453+
expect(styles.cssText).toBe('');
454+
});
455+
359456
});

ts/output/chtml/Wrapper.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,15 @@ export class ChtmlWrapper<N, T, D> extends CommonWrapper<
444444
const adaptor = this.adaptor;
445445
if (align === 'center' || align === 'left') {
446446
const L = this.getBBox().L;
447-
adaptor.setStyle(chtml, 'margin-left', this.em(shift + L));
447+
if (shift + L) {
448+
adaptor.setStyle(chtml, 'margin-left', this.em(shift + L));
449+
}
448450
}
449451
if (align === 'center' || align === 'right') {
450452
const R = this.getBBox().R;
451-
adaptor.setStyle(chtml, 'margin-right', this.em(-shift + R));
453+
if (shift + R) {
454+
adaptor.setStyle(chtml, 'margin-right', this.em(-shift + R));
455+
}
452456
}
453457
}
454458

ts/util/Styles.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,12 @@ export class Styles {
365365
combine: combineTRBL,
366366
},
367367

368+
margin: {
369+
children: TRBL,
370+
split: splitTRBL,
371+
combine: combineTRBL,
372+
},
373+
368374
border: {
369375
children: TRBL,
370376
split: splitSame,

0 commit comments

Comments
 (0)