-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MathML support #12836
Add MathML support #12836
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
Hey @googlebot - I signed it! |
CLAs look good, thanks! |
@@ -0,0 +1,69 @@ | |||
# |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look at Contributing Validator Rules. The format for allowing the script tag has been simplified greatly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will do - thanks for the feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed the extensions/amp-mathml/validator-amp-mathml.protoascii file in f6d93f3 - I still need to add some valid and invalid test cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamsilverstein Thanks so much for contributing this. Great initial PR. Left bunch of comments.
Reading resizing, we only resize with and AMP components are block elements by default. User would need to use flex or other parent CSS ways to make this inline. We won't do resizing for width.
3p/mathml.js
Outdated
@@ -0,0 +1,68 @@ | |||
/** | |||
* Copyright 2017 The AMP HTML Authors. All Rights Reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2018 ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yea; sorry, i started by copying an existing component, I'll clean this up.
3p/mathml.js
Outdated
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
console.log( 'mathml.js' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't forget to remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:doh:
3p/mathml.js
Outdated
import {user} from '../src/log'; | ||
|
||
/** | ||
* Get the correct script for the gist. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the mathml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, thanks
3p/mathml.js
Outdated
delete data.height; | ||
const div = document.createElement('div'); | ||
div.setAttribute('id','mathmlformula'); | ||
div.innerHTML = data.formula; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
must be div.textContent =
otherwise this crease an XSS vulnerability given formula
is not sanitized. textContent
should be fine for Latex and Ascii Math. Worht testing for MathML, if it does not work, we unfortunately need to remove support for MathML as input and stick to LaText and ASCII Math since we don't have enough utilities to safely sanitize mathml input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting, ok i'll change and do some testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far my test cases look fine after the change to textContent
, I'll add some more samples from https://developer.mozilla.org/en-US/docs/Mozilla/MathML_Project/MathML_Torture_Test to my example page
3p/mathml.js
Outdated
const div = document.createElement('div'); | ||
div.setAttribute('id','mathmlformula'); | ||
div.innerHTML = data.formula; | ||
document.body.appendChild(div); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
global.document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, will change - what is the context/reason behind global.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may not be the current window in certain situations where an AMP doc is embedded differently.
3p/mathml.js
Outdated
document.body.appendChild(div); | ||
MathJax.Hub.Queue( function () { | ||
const rendered = document.getElementById('MathJax-Element-1-Frame'); | ||
context.requestResize( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updateDimensions
is okay in this case ( requestResize
is not guaranteed to resize). We make exceptions for updateDimensions
per component and this should be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also mathml
needs to be added to updateDimensionsEnabled_()
method in ampcontext-integration.js
file for it to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting, will add
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aghassemi when adding this I noticed on a line I was touching that the check for 'github' isn't using a strict equality check, see https://github.com/ampproject/amphtml/blob/master/3p/ampcontext-integration.js#L72
This should be ===
, right? Should I open a separate pull request for this issue? I don't want to introduce unrelated changes here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our JS compiler handles discrepencies between ==
and ===
so it is fine in practices, would be nice for consistency, you can change it here in this PR
/** @override */ | ||
buildCallback() { | ||
const formula = this.element.getAttribute('formula'); | ||
if (!formula || '' === formula) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's have
user().assert(
data.formula,
'The formula attribute is required for <amp-mathml> %s',
data.element);
here instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that bit is in mathml.js, i removed the buildCallback entirely, it seems superfluous
super(element); | ||
|
||
/** @private {!Element} */ | ||
this.container_ = this.win.document.createElement('div'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not used, remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@@ -0,0 +1,27 @@ | |||
<!doctype html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep this in the extension folder. Also needs a .out
file. See https://github.com/ampproject/amphtml/blob/master/extensions/amp-sidebar/0.1/test/validator-amp-sidebar.html and https://github.com/ampproject/amphtml/blob/master/extensions/amp-sidebar/0.1/test/validator-amp-sidebar.out as a good sample.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, i have an uncommitted out file that i think was generated when i started, I'll check that and commit it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the file, but I am still missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this file to extensions/amp-mathml/0.1/test/validator-amp-mathml.html
. The out file will be extensions/amp-mathml/0.1/test/validator-amp-mathml.out
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See here for an example extensions test directory with an .html and .out.
yarn.lock
Outdated
@@ -178,6 +178,12 @@ [email protected], acorn-globals@^4.0.0: | |||
dependencies: | |||
acorn "^5.0.0" | |||
|
|||
acorn-globals@^3.1.0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, will do
@aghassemi thanks for the careful review and detailed feedback. I will work on all of the points raised and get back to you when I am ready for another review. I still have a question about the resizing: is it possible to get the iframe to resize its width as well as its height, currently my listener only changes height. any tips to getting this working? |
@aghassemi You are very welcome, thanks for your assistance along the way. Adding tests later sounds good, please tag me in the PR as I would like to see and learn from how you add these. I fixed the linting errors and added the OWNERS.yaml file as well as changing the tagname to allcaps as suggested by @honeybadgerdontcare. Did you see my question above about clearing the valtador errors (#12836 (comment)) - unless the allcaps change in 6fdb6e4 fixes them, I'm not sure how to correct those. On a related note, I'm blocked from running |
@aghassemi I think I have fixed all the warnings other than the validator messages I mentioned above that I am not sure how to clear. Please let me know how to fix or just go for it and get the validator passing. Thanks! |
missed the earlier comment from @honeybadgerdontcare - move the test and out files into the test folder in 98d0039 |
@adamsilverstein it looks like you're still missing the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I approve protoascii changes. Test file changes can come later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I approve protoascii changes. Test file changes can come later.
@honeybadgerdontcare Thanks for your patience with me as I'm learning the ropes around here :) I thought this was the correct location for the I'll go ahead and open an issue as you suggested and let you take care of the rest, thank you! |
@honeybadgerdontcare I created an issue but don't have the capability to assign it to you: #12973 |
I've taken the issue. The problem, or at least the easiest to see, is with the out file. It doesn't include the actual |
@honeybadgerdontcare thanks so much for your assistance, I removed the test files in 85bf039. |
@aghassemi all checks have passed :) |
@adamsilverstein merged! I am super happy to see large contributions like this from the community. Thanks again Adam. /cc @mrjoro |
Wooohooo! Thanks for all your shepherding @aghassemi I learned a ton about AMP along the way, and this feature will be a big improvement for our client's site. How long does it take for this feature to make it to production/the wild? |
@adamsilverstein For production use, ~3 weeks (Validator changes take a bit to make it to prod. A comment will be added to this PR when validation rules are in prod). Folks can start experimenting with it in next Dev Channel (tomorrow) however. |
* Add an amp-video test that shows which tagspec is picked for errors. * Revision bump for ampproject#12654 * Revision bump for ampproject#12836 * Make sure the light validator doesn't run amp4ads tests.
* Add an amp-video test that shows which tagspec is picked for errors. * Revision bump for ampproject#12654 * Revision bump for ampproject#12836 * Make sure the light validator doesn't run amp4ads tests.
Implements MathML support via an Iframe and the CDN hosted MathJax script. Fixes #12800
Includes a few example of formulas, I wasn't sure how to make these small to begin with, in my testing they started large then resized smaller when the formula rendered.