mathjax / MathJax-node

MathJax for Node
Apache License 2.0
616 stars 97 forks source link

jsdom no longer drops xlink prefix #386

Closed pkra closed 6 years ago

pkra commented 6 years ago

It looks like Mathjax-node no longer needs to fix the svg output in https://github.com/mathjax/MathJax-node/blob/8386df93e4f283fb4ea16a7b48612edc7cea7361/lib/main.js#L705.

dpvc commented 6 years ago

I am not able to reproduce this. If I remove the line you cite, then the xlink: prefix doesn't show up.

For example, with

var mj = require("./lib/main.js");

mj.typeset({
    math: "x",
    format: "TeX",
    svg: true
}, function (data) {
    console.log(data.svg);
});

the current version of mathjx-node (unaltered) produces

<svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.33ex" height="1.676ex" style="vertical-align: -0.338ex;" viewBox="0 -576.1 572.5 721.6" role="img" focusable="false" xmlns="http://www.w3.org/2000/svg" aria-labelledby="MathJax-SVG-1-Title">
<title id="MathJax-SVG-1-Title">x</title>
<defs aria-hidden="true">
<path stroke-width="1" id="E1-MJMATHI-78" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path>
</defs>
<g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)" aria-hidden="true">
 <use xlink:href="#E1-MJMATHI-78" x="0" y="0"></use>
</g>
</svg>

while removing the replace() that you indicate produces

<svg xmlns:xlink="http://www.w3.org/1999/xlink" width="1.33ex" height="1.676ex" style="vertical-align: -0.338ex;" viewBox="0 -576.1 572.5 721.6" role="img" focusable="false" xmlns="http://www.w3.org/2000/svg" aria-labelledby="MathJax-SVG-1-Title">
<title id="MathJax-SVG-1-Title">x</title>
<defs aria-hidden="true">
<path stroke-width="1" id="E1-MJMATHI-78" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path>
</defs>
<g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)" aria-hidden="true">
<use href="#E1-MJMATHI-78" x="0" y="0"></use>
</g>
</svg>

Note that the xlink is present in the first and not in the second.

Do you get a different result?

pkra commented 6 years ago

Do you get a different result?

Sorry, I should've made sure. I had a different result while working on upgrading mathjax-node-sre. I'll take another look and report back.

pkra commented 6 years ago

Ok, I can't reproduce it on mathjax-node. But it seems in mathjax-node-sre I can drop the same line https://github.com/pkra/mathjax-node-sre/blob/master/lib/main.js#L75. Random guess: jsdom now preserves the prefix once it's there but still doesn't understand how mathjax(-node) creates them.

pkra commented 6 years ago

And apologies for the noise.

pkra commented 6 years ago

I have to correct myself. After a fresh npm install, I can't reproduce this downstream at mathjax-node-sre anymore. No idea what I had done previously to fix it. Sorry about that.

pkra commented 6 years ago

Let me "well actually" myself. I don't see this downstream unless I have speaktText:true there. Maybe https://github.com/mathjax/MathJax-node/issues/386#issuecomment-364033003 was true after all; I'll let you know if I find anything.

pkra commented 6 years ago

D'oh -- it's been a while since I worked on that code! If speakTrue:false, then mathjax-node-sre just passes mathjax-node's result. And of course that is fixed already.

dpvc commented 6 years ago

OK, thanks for tracking it down. If I understand the comments above, we still need the replace() that you link to above.

pkra commented 6 years ago

If I understand the comments above, we still need the replace() that you link to above.

That's correct. We should probably file an upstream bug some time (there are still browsers that choke on SVGs without the xlink prefix).

pkra commented 6 years ago

FYI I think the underlying issue is https://github.com/jsdom/jsdom/issues/1624

pkra commented 6 years ago

As pointed out there, jsdom matches browsers and in fact client-side MathJax also lacks the prefix. So this sounds like an XML vs HTML conflicts.