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 a linkedom adaptor (mathjax/MathJax#2833) #774

Merged
merged 2 commits into from
Feb 22, 2022
Merged

Add a linkedom adaptor (mathjax/MathJax#2833) #774

merged 2 commits into from
Feb 22, 2022

Conversation

dpvc
Copy link
Member

@dpvc dpvc commented Feb 8, 2022

This PR adds an adaptor for the linkedom node-based DOM implementation.

Resolves issue mathjax/MathJax#2833.

@swamidass
Copy link

Thanks @dpvc . When do you think this will get integrated into MathJax?

@dpvc
Copy link
Member Author

dpvc commented Feb 13, 2022

It will be merged into develop when the code is reviewed, and into master for the next release, which is still several months away.

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.

As this is now the third adaptor which share very similar components (with liteAdaptor, jsdomAdaptor) I believe that it is time to refactor the common elements into an abstract superclass.

@zorkow
Copy link
Member

zorkow commented Feb 22, 2022

I believe that it is time to refactor the common elements into an abstract superclass.

As a common superclass might not fit, as some inherit from HTMLAdaptor maybe could have at least have common utilities to the static elements like OPTIONS and cjkPattern.

@dpvc
Copy link
Member Author

dpvc commented Feb 22, 2022

As this is now the third adaptor which share very similar components (with liteAdaptor, jsdomAdaptor) I believe that it is time to refactor the common elements into an abstract superclass.

I did that in the next PR. I didn't do it here because I referred the original requester to this PR to get the linkedom adaptor until this is public. So the refactoring was in a separate PR.

As a common superclass might not fit, as some inherit from HTMLAdaptor maybe could have at least have common utilities to the static elements like OPTIONS and cjkPattern.

I considered that, but used a mix-in instead.

@dpvc dpvc added this to the 3.2.1 milestone Feb 22, 2022
@zorkow
Copy link
Member

zorkow commented Feb 22, 2022

I considered that, but used a mix-in instead.

I also thought about that. But having tried to explain mixins here for an afternoon, I am now aware that they add considerable hurdles to understanding the code.
I always liked that about C++ (or CLOS) having multiple inheritance, friends, ...

@dpvc
Copy link
Member Author

dpvc commented Feb 22, 2022

But having tried to explain mixins here for an afternoon, I am now aware that they add considerable hurdles to understanding the code.

Yes, some can be complicated, and not quite as flexible as I would like. But the one used here is less complicated than the more sophisticated ones need for MathItem and MathDocument render actions (which are pretty horrible). So I thought this was reasonable.

I, too, which there were an easier way to deal with multiple inheritance.

@dpvc dpvc merged commit 6ab652e into develop Feb 22, 2022
@dpvc dpvc deleted the issue2833 branch February 22, 2022 18:46
return this.outerHTML(node);
}

/**

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

(Sorry, see my comment below. I entered it in the wrong box.)

@dpvc
Copy link
Member Author

dpvc commented Feb 24, 2022

Both of the links you provide are only polyfills to get a version of getComputedStyle() to work in Internet Explorer (and older versions of Opera). They rely on currentStyle, which is a non-standard IE-only property. So this doesn't work in linkedom or jsdom or liteDOM, none of which implement this.

To get a version of getComputedStyle() to work in these settings, one would have to interpret all the CSS files, and all the inheritance involved in the CSS cascade. Doing that for all elements just to be able to use getComputedStyle() in the few cases MathJax needs it would be a huge performance hit. Even trying to do it just for the limited properties MathJax needs (e.g., the font size) would still require loading and interpreting all the CSS files, and determining which selectors apply to the element and every parent element until one of them sets the needed property. This is still a pretty big undertaking, and a non-trivial bit of coding. If someone wants to implement that, I'd be happy to entertain it.

@swamidass
Copy link

Got it. I see the problem. If it's a similar problem with the other adapters, it shouldn't be a show stopper here.

@dpvc
Copy link
Member Author

dpvc commented Feb 24, 2022

Yes, all the node-based adaptors have the same issue. The getComputedStyle() function only works in the browser.

@swamidass
Copy link

@dpvc thank you for the detailed help you've offered me here. I really appreciate it.

I've been trying to figure out how to use the develop branch in my project to make use of the linkedom adapter, but it seems Mathjax has a confused build process that npm can't understand.

I thought that this would work,

npm install mathjax/MathJax-src#develop

but it doesn't. This does pull the development version into node_packages, but it doesn't actually build anything. Is it possible that this could be fixed by adding the right "build" script to package.json in the develop branch? Or is there another trick for importing and building mathjax from github using npm? Or is there a way to get the development branch from the npm registry somehow?

@dpvc
Copy link
Member Author

dpvc commented Feb 28, 2022

You are right that the GitHub repository doesn't include the compiled or webpacked versions of the files, and doesn't build those on install. You would need to

cd node_modules/mathjax-full
npm install
npm run -s compile
npm run -s make-components

The last line is only needed if you are using one of the component-based means of accessing MathJax. If you use the direct approach, only the first three lines are needed.

@dpvc
Copy link
Member Author

dpvc commented Feb 28, 2022

(sorry, left out one line. You probably need npm install before npm run -s compile. I've added it to my comment above)

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.

3 participants