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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Safe extension and component #514

Merged
merged 3 commits into from
Jul 6, 2020
Merged

Add Safe extension and component #514

merged 3 commits into from
Jul 6, 2020

Conversation

dpvc
Copy link
Member

@dpvc dpvc commented Jun 11, 2020

This PR ports the Safe extension from v2 to v3. It hooks into the MathML input jax via the filterAttribute()method that was set up for that, and via a new filterClassList() for handling the class attribute. Some adjustments were made to make handling the filters a bit easier.

It hooks into the TeX input jax as a post filter. In v2, it hooked into the TeX parser itself so that it only filtered user-supplied values, but that is hard to maintain, as it must be aware of all the extensions and when user input is allowed. The post-filter avoids that, at the expense of having to look at all the attributes of all the elements, so it is less efficient, but more reliable.

This PR includes a component for the safe extension, so it can be loaded from the CDN. it also corrects an error in handling fontsize in the common/Wrapper.ts file.

@dpvc dpvc added this to the v3.1.0 milestone Jun 11, 2020
@dpvc dpvc requested a review from zorkow June 11, 2020 19:01
Copy link
Member

@zorkow zorkow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly typos. O/w a couple of points for clarification.

const attributes = node.attributes.getAllAttributes();
for (const id of Object.keys(attributes)) {
if (this.filterAttributes.hasOwnProperty(id)) {
const value = this.filterMethods[this.filterAttributes[id]](this, attributes[id]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it certain that for every filterAttribute there will be a filterMethod?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing is certain. What are you suggesting? Checking and reporting an error if not? Isn't that what will happen anyway if not? Because this will be called on every attribute on every node, it should be kept as slim as possible. If someone adds a filterAttribute without creating the corresponding filterMethod, then they will get an error message at this point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if we should catch that error at this point, i.e., if the filterMethod does not exist, then we could simply continue in the loop, or throw an explicit error, rather than get a undefined is not a function error.

@dpvc
Copy link
Member Author

dpvc commented Jun 29, 2020

I've made the fixes you requested.

@dpvc dpvc requested a review from zorkow June 29, 2020 17:35
Copy link
Member

@zorkow zorkow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

@dpvc dpvc merged commit 1cf6ec9 into develop Jul 6, 2020
@dpvc dpvc deleted the safe-extension branch July 6, 2020 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants