Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 amp-mathml: Add support for non-block mode; fixes #19420 #19436

Merged
merged 7 commits into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 15 additions & 10 deletions 3p/mathml.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ export function mathml(global, data) {

getMathmlJs(
global,
'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML',
'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML',
mathjax => {
// Dimensions are given by the parent frame.
delete data.width;
delete data.height;
const div = document.createElement('div');
div.setAttribute('id','mathmlformula');
div.setAttribute('id', 'mathmlformula');
div.textContent = data.formula;
setStyle(div, 'visibility', 'hidden');
global.document.body.appendChild(div);
Expand All @@ -62,15 +62,20 @@ export function mathml(global, data) {
mathjax.Hub.Queue(function() {
const rendered = document.getElementById('MathJax-Element-1-Frame');
// Remove built in mathjax margins.
const display = document.getElementsByClassName('MJXc-display');
if (display[0]) {
display[0].setAttribute('style','margin-top:0;margin-bottom:0');
context.requestResize(
rendered./*OK*/offsetWidth,
rendered./*OK*/offsetHeight
);
setStyle(div, 'visibility', 'visible');
let display = document.getElementsByClassName('MJXc-display');
if (!display[0]) {
const span = document.createElement('span');
span.setAttribute('class', 'mjx-chtml MJXc-display');
span.appendChild(rendered);
div.appendChild(span);
display = document.getElementsByClassName('MJXc-display');
}
display[0].setAttribute('style','margin-top:0;margin-bottom:0');
context.requestResize(
rendered./*OK*/offsetWidth,
rendered./*OK*/offsetHeight
);
setStyle(div, 'visibility', 'visible');
});
}
);
Expand Down
6 changes: 3 additions & 3 deletions examples/amp-mathml.amp.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ <h2>Cauchy's Integral Formula</h2>
<h2>Double angle formula for Cosines</h2>
<amp-mathml
layout="container"
data-formula="\[ \cos(胃+蠁)=\cos(胃)\cos(蠁)鈭抃sin(胃)\sin(蠁) \]">
data-formula="$$ \cos(胃+蠁)=\cos(胃)\cos(蠁)鈭抃sin(胃)\sin(蠁) $$">
</amp-mathml>
<h2>Inline formula.</h2>
This is an example of a formula placed inline in the middle of a block of text. <amp-mathml layout="container" inline data-formula="\[ \cos(胃+蠁) \]"></amp-mathml> This shows how the formula will fit inside a block of text and can be styled with CSS.
<h2>Inline formula</h2>
<p>This is an example of a formula of <amp-mathml layout="container" inline data-formula="`x`"></amp-mathml>, <amp-mathml layout="container" inline data-formula="\(x = {-b \pm \sqrt{b^2-4ac} \over 2a}\)"></amp-mathml> placed inline in the middle of a block of text. <amp-mathml layout="container" inline data-formula="\( \cos(胃+蠁) \)"></amp-mathml> This shows how the formula will fit inside a block of text and can be styled with CSS.</p>
</body>
</html>
1 change: 1 addition & 0 deletions extensions/amp-mathml/0.1/amp-mathml.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@

amp-mathml[inline] {
display: inline-block;
vertical-align: middle;
}
2 changes: 1 addition & 1 deletion extensions/amp-mathml/0.1/test/validator-amp-mathml.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<body>
<!-- Valid -->
<amp-mathml layout="container" data-formula="\[x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\]"></amp-mathml>
<amp-mathml layout="container" inline data-formula="\[x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\]"></amp-mathml>
<amp-mathml layout="container" inline data-formula="\(x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\)"></amp-mathml>
<!-- Invalid: unsupported layout value -->
<amp-mathml layout="responsive" width="10px" height="10px" data-formula="\[x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\]"></amp-mathml>
<!-- Invalid: missing formula -->
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-mathml/0.1/test/validator-amp-mathml.out
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ FAIL
| <body>
| <!-- Valid -->
| <amp-mathml layout="container" data-formula="\[x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\]"></amp-mathml>
| <amp-mathml layout="container" inline data-formula="\[x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\]"></amp-mathml>
| <amp-mathml layout="container" inline data-formula="\(x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\)"></amp-mathml>
| <!-- Invalid: unsupported layout value -->
| <amp-mathml layout="responsive" width="10px" height="10px" data-formula="\[x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\]"></amp-mathml>
>> ^~~~~~~~~
Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-mathml/amp-mathml.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ This extension creates an iframe and renders a MathML formula.
#### Example: Double angle formula for Cosines

```html
<amp-mathml layout="container" data-formula="\[ \cos(胃+蠁)=\cos(胃)\cos(蠁)鈭抃sin(胃)\sin(蠁) \]">
<amp-mathml layout="container" data-formula="$$ \cos(胃+蠁)=\cos(胃)\cos(蠁)鈭抃sin(胃)\sin(蠁) $$">
</amp-mathml>
```
#### Example: Inline formula

This is an example of a formula placed inline in the middle of a block of text. `<amp-mathml layout="container" inline data-formula="\[ \cos(胃+蠁) \]"></amp-mathml>` This shows how the formula will fit inside a block of text and can be styled with CSS.
This is an example of a formula of ``<amp-mathml layout="container" inline data-formula="`x`"></amp-mathml>``, `<amp-mathml layout="container" inline data-formula="\(x = {-b \pm \sqrt{b^2-4ac} \over 2a}\)"></amp-mathml>` placed inline in the middle of a block of text. `<amp-mathml layout="container" inline data-formula="\( \cos(胃+蠁) \)"></amp-mathml>` This shows how the formula will fit inside a block of text and can be styled with CSS.

## Attributes

Expand Down