MCPcopy
hub / github.com/ampproject/amphtml / mathml

Function mathml

3p/mathml.js:28–76  ·  view source on GitHub ↗
(global, data)

Source from the content-addressed store, hash-verified

26 * @param {!Object} data
27 */
28export function mathml(global, data) {
29 userAssert(
30 data.formula,
31 'The formula attribute is required for <amp-mathml> %s',
32 data.element
33 );
34
35 getMathmlJs(
36 global,
37 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML',
38 (mathjax) => {
39 // Dimensions are given by the parent frame.
40 delete data.width;
41 delete data.height;
42 const div = document.createElement('div');
43 div.setAttribute('id', 'mathmlformula');
44 div.textContent = data.formula;
45 setStyle(div, 'visibility', 'hidden');
46 global.document.body.appendChild(div);
47 mathjax.Hub.Config({
48 showMathMenu: false,
49 // (#26082): From a11y perspective, user should not be able to tab to
50 // the math formula which has no functionality to interact with. This
51 // configuration removes the formula from the tab-index.
52 menuSettings: {
53 inTabOrder: false,
54 },
55 });
56 mathjax.Hub.Queue(function () {
57 const rendered = document.getElementById('MathJax-Element-1-Frame');
58 // Remove built in mathjax margins.
59 let display = document.getElementsByClassName('MJXc-display');
60 if (!display[0]) {
61 const span = document.createElement('span');
62 span.setAttribute('class', 'mjx-chtml MJXc-display');
63 span.appendChild(rendered);
64 div.appendChild(span);
65 display = document.getElementsByClassName('MJXc-display');
66 }
67 display[0].setAttribute('style', 'margin-top:0;margin-bottom:0');
68 context.requestResize(
69 rendered./*OK*/ offsetWidth,
70 rendered./*OK*/ offsetHeight
71 );
72 setStyle(div, 'visibility', 'visible');
73 });
74 }
75 );
76}

Callers

nothing calls this directly

Calls 6

userAssertFunction · 0.90
setStyleFunction · 0.90
getMathmlJsFunction · 0.85
requestResizeMethod · 0.80
setAttributeMethod · 0.45
getElementByIdMethod · 0.45

Tested by

no test coverage detected