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

invalid javascript @ generated object keys #72

Closed
4 tasks done
Enteleform opened this issue Jan 13, 2022 · 21 comments
Closed
4 tasks done

invalid javascript @ generated object keys #72

Enteleform opened this issue Jan 13, 2022 · 21 comments
Labels
👀 no/external This makes more sense somewhere else 👎 phase/no Post cannot or will not be acted on

Comments

@Enteleform
Copy link
Contributor

Initial checklist

Affected packages and versions

rehype-mathjax: 4.0.2

Link to runnable example

No response

Steps to reproduce

// @ vite.config.js
{
  plugins: [
    XDM({
      rehypePlugins: [Rehype_MathJax],
      remarkPlugins: [Remark_Math   ],
    })
  ]
}

Expected behavior

Example snippet

Lift($L$) can be determined by Lift Coefficient ($C_L$) like the following equation.

should compile from an mdx file without error.

Actual behavior

Browser Error:

Uncaught (in promise) SyntaxError: Unexpected token '-'

image

It seems that the error would be prevented by wrapping the generated mdx-container key in quotes.

Through trial & error I found that this issue:

  • occurs when parsing mdx files via either mdx-js or xdm
  • does not occur when swapping rehype-katex in place of rehype-mathjax

Runtime

Node v16

Package manager

yarn v1

OS

Windows

Build and bundle tools

Vite

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Jan 13, 2022
wooorm added a commit to wooorm/xdm that referenced this issue Jan 13, 2022
@wooorm
Copy link
Member

wooorm commented Jan 13, 2022

Thanks for the report! I fixed it in xdm (expect a release in a minute), and will release it in MDX in the next RC / actual release (a week or two?).
I’ll close this issue here because there are no code changes required in remarkjs/remark-math!

@wooorm wooorm added the 👀 no/external This makes more sense somewhere else label Jan 13, 2022
@wooorm wooorm closed this as completed Jan 13, 2022
@wooorm wooorm added the 👎 phase/no Post cannot or will not be acted on label Jan 13, 2022
@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Jan 13, 2022
@Enteleform
Copy link
Contributor Author

@wooorm

Awesome, thanks for the quick fix!

Managed to get it working chtml, but not svg:

image

Based on the docs it seems like no additional config should be required for rehype-mathjax/svg.js to work, not sure if I'm missing something here?

Can provide more info if needed!


vite.config.js
// rehype-katex
rehypePlugins: [Rehype_KaTeX] // + css @ index.html

// rehype-mathjax/chtml.js
rehypePlugins: [
  [Rehype_MathJax, {
    chtml: {
      fontURL: "https://cdn.jsdelivr.net/npm/mathjax@3/components/output/chtml/fonts/woff-v2"
    }
  }]
]

// rehype-mathjax/svg.js
rehypePlugins: [Rehype_MathJax]
Example.mdx
# Inline

$\sqrt{a^2 + b^2}$

Lift($L$) can be determined by Lift Coefficient ($C_L$) like the following equation.


# Block

$
L = \frac{1}{2} \rho v^2 S C_L
$
Rendered-Example.html
<h1>Inline</h1>
<p><span class="math math-inline">
    <mjx-container class="MathJax"><svg xmlns="http://www.w3.org/2000/svg" width="8.838ex" height="2.398ex" role="img"
        focusable="false" viewBox="0 -966.5 3906.6 1060" xmlnsXlink="http://www.w3.org/1999/xlink">
        <defs>
          <path id="MJX-1-TEX-N-221A"
            d="M95 178Q89 178 81 186T72 200T103 230T169 280T207 309Q209 311 212 311H213Q219 311 227 294T281 177Q300 134 312 108L397 -77Q398 -77 501 136T707 565T814 786Q820 800 834 800Q841 800 846 794T853 782V776L620 293L385 -193Q381 -200 366 -200Q357 -200 354 -197Q352 -195 256 15L160 225L144 214Q129 202 113 190T95 178Z">
          </path>
          <path id="MJX-1-TEX-I-1D44E"
            d="M33 157Q33 258 109 349T280 441Q331 441 370 392Q386 422 416 422Q429 422 439 414T449 394Q449 381 412 234T374 68Q374 43 381 35T402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487Q506 153 506 144Q506 138 501 117T481 63T449 13Q436 0 417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157ZM351 328Q351 334 346 350T323 385T277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q217 26 254 59T298 110Q300 114 325 217T351 328Z">
          </path>
          <path id="MJX-1-TEX-N-32"
            d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z">
          </path>
          <path id="MJX-1-TEX-N-2B"
            d="M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z">
          </path>
          <path id="MJX-1-TEX-I-1D44F"
            d="M73 647Q73 657 77 670T89 683Q90 683 161 688T234 694Q246 694 246 685T212 542Q204 508 195 472T180 418L176 399Q176 396 182 402Q231 442 283 442Q345 442 383 396T422 280Q422 169 343 79T173 -11Q123 -11 82 27T40 150V159Q40 180 48 217T97 414Q147 611 147 623T109 637Q104 637 101 637H96Q86 637 83 637T76 640T73 647ZM336 325V331Q336 405 275 405Q258 405 240 397T207 376T181 352T163 330L157 322L136 236Q114 150 114 114Q114 66 138 42Q154 26 178 26Q211 26 245 58Q270 81 285 114T318 219Q336 291 336 325Z">
          </path>
        </defs>
        <g stroke="currentColor" fill="currentColor" strokeWidth="0" transform="scale(1,-1)">
          <g data-mml-node="math">
            <g data-mml-node="msqrt">
              <g transform="translate(853,0)">
                <g data-mml-node="msup">
                  <g data-mml-node="mi">
                    <use data-c="1D44E" xlinkHref="#MJX-1-TEX-I-1D44E"></use>
                  </g>
                  <g data-mml-node="mn" transform="translate(562,289) scale(0.707)">
                    <use data-c="32" xlinkHref="#MJX-1-TEX-N-32"></use>
                  </g>
                </g>
                <g data-mml-node="mo" transform="translate(1187.8,0)">
                  <use data-c="2B" xlinkHref="#MJX-1-TEX-N-2B"></use>
                </g>
                <g data-mml-node="msup" transform="translate(2188,0)">
                  <g data-mml-node="mi">
                    <use data-c="1D44F" xlinkHref="#MJX-1-TEX-I-1D44F"></use>
                  </g>
                  <g data-mml-node="mn" transform="translate(462,289) scale(0.707)">
                    <use data-c="32" xlinkHref="#MJX-1-TEX-N-32"></use>
                  </g>
                </g>
              </g>
              <g data-mml-node="mo" transform="translate(0,106.5)">
                <use data-c="221A" xlinkHref="#MJX-1-TEX-N-221A"></use>
              </g>
              <rect width="3053.6" height="60" x="853" y="846.5"></rect>
            </g>
          </g>
        </g>
      </svg></mjx-container>
  </span></p>
<p>Lift(<span class="math math-inline">
    <mjx-container class="MathJax"><svg xmlns="http://www.w3.org/2000/svg" width="1.541ex" height="1.545ex" role="img"
        focusable="false" viewBox="0 -683 681 683" xmlnsXlink="http://www.w3.org/1999/xlink">
        <defs>
          <path id="MJX-2-TEX-I-1D43F"
            d="M228 637Q194 637 192 641Q191 643 191 649Q191 673 202 682Q204 683 217 683Q271 680 344 680Q485 680 506 683H518Q524 677 524 674T522 656Q517 641 513 637H475Q406 636 394 628Q387 624 380 600T313 336Q297 271 279 198T252 88L243 52Q243 48 252 48T311 46H328Q360 46 379 47T428 54T478 72T522 106T564 161Q580 191 594 228T611 270Q616 273 628 273H641Q647 264 647 262T627 203T583 83T557 9Q555 4 553 3T537 0T494 -1Q483 -1 418 -1T294 0H116Q32 0 32 10Q32 17 34 24Q39 43 44 45Q48 46 59 46H65Q92 46 125 49Q139 52 144 61Q147 65 216 339T285 628Q285 635 228 637Z">
          </path>
        </defs>
        <g stroke="currentColor" fill="currentColor" strokeWidth="0" transform="scale(1,-1)">
          <g data-mml-node="math">
            <g data-mml-node="mi">
              <use data-c="1D43F" xlinkHref="#MJX-2-TEX-I-1D43F"></use>
            </g>
          </g>
        </g>
      </svg></mjx-container>
  </span>) can be determined by Lift Coefficient (<span class="math math-inline">
    <mjx-container class="MathJax"><svg xmlns="http://www.w3.org/2000/svg" width="2.895ex" height="1.934ex" role="img"
        focusable="false" viewBox="0 -705 1279.5 855" xmlnsXlink="http://www.w3.org/1999/xlink">
        <defs>
          <path id="MJX-3-TEX-I-1D436"
            d="M50 252Q50 367 117 473T286 641T490 704Q580 704 633 653Q642 643 648 636T656 626L657 623Q660 623 684 649Q691 655 699 663T715 679T725 690L740 705H746Q760 705 760 698Q760 694 728 561Q692 422 692 421Q690 416 687 415T669 413H653Q647 419 647 422Q647 423 648 429T650 449T651 481Q651 552 619 605T510 659Q484 659 454 652T382 628T299 572T226 479Q194 422 175 346T156 222Q156 108 232 58Q280 24 350 24Q441 24 512 92T606 240Q610 253 612 255T628 257Q648 257 648 248Q648 243 647 239Q618 132 523 55T319 -22Q206 -22 128 53T50 252Z">
          </path>
          <path id="MJX-3-TEX-I-1D43F"
            d="M228 637Q194 637 192 641Q191 643 191 649Q191 673 202 682Q204 683 217 683Q271 680 344 680Q485 680 506 683H518Q524 677 524 674T522 656Q517 641 513 637H475Q406 636 394 628Q387 624 380 600T313 336Q297 271 279 198T252 88L243 52Q243 48 252 48T311 46H328Q360 46 379 47T428 54T478 72T522 106T564 161Q580 191 594 228T611 270Q616 273 628 273H641Q647 264 647 262T627 203T583 83T557 9Q555 4 553 3T537 0T494 -1Q483 -1 418 -1T294 0H116Q32 0 32 10Q32 17 34 24Q39 43 44 45Q48 46 59 46H65Q92 46 125 49Q139 52 144 61Q147 65 216 339T285 628Q285 635 228 637Z">
          </path>
        </defs>
        <g stroke="currentColor" fill="currentColor" strokeWidth="0" transform="scale(1,-1)">
          <g data-mml-node="math">
            <g data-mml-node="msub">
              <g data-mml-node="mi">
                <use data-c="1D436" xlinkHref="#MJX-3-TEX-I-1D436"></use>
              </g>
              <g data-mml-node="mi" transform="translate(748,-150) scale(0.707)">
                <use data-c="1D43F" xlinkHref="#MJX-3-TEX-I-1D43F"></use>
              </g>
            </g>
          </g>
        </g>
      </svg></mjx-container>
  </span>) like the following equation.</p>
<h1>Block</h1>
<p><span class="math math-inline">
    <mjx-container class="MathJax"><svg xmlns="http://www.w3.org/2000/svg" width="13.962ex" height="2.737ex"
        role="img" focusable="false" viewBox="0 -864.9 6171.2 1209.9" xmlnsXlink="http://www.w3.org/1999/xlink">
        <defs>
          <path id="MJX-4-TEX-I-1D43F"
            d="M228 637Q194 637 192 641Q191 643 191 649Q191 673 202 682Q204 683 217 683Q271 680 344 680Q485 680 506 683H518Q524 677 524 674T522 656Q517 641 513 637H475Q406 636 394 628Q387 624 380 600T313 336Q297 271 279 198T252 88L243 52Q243 48 252 48T311 46H328Q360 46 379 47T428 54T478 72T522 106T564 161Q580 191 594 228T611 270Q616 273 628 273H641Q647 264 647 262T627 203T583 83T557 9Q555 4 553 3T537 0T494 -1Q483 -1 418 -1T294 0H116Q32 0 32 10Q32 17 34 24Q39 43 44 45Q48 46 59 46H65Q92 46 125 49Q139 52 144 61Q147 65 216 339T285 628Q285 635 228 637Z">
          </path>
          <path id="MJX-4-TEX-N-3D"
            d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z">
          </path>
          <path id="MJX-4-TEX-N-31"
            d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z">
          </path>
          <path id="MJX-4-TEX-N-32"
            d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z">
          </path>
          <path id="MJX-4-TEX-I-1D70C"
            d="M58 -216Q25 -216 23 -186Q23 -176 73 26T127 234Q143 289 182 341Q252 427 341 441Q343 441 349 441T359 442Q432 442 471 394T510 276Q510 219 486 165T425 74T345 13T266 -10H255H248Q197 -10 165 35L160 41L133 -71Q108 -168 104 -181T92 -202Q76 -216 58 -216ZM424 322Q424 359 407 382T357 405Q322 405 287 376T231 300Q217 269 193 170L176 102Q193 26 260 26Q298 26 334 62Q367 92 389 158T418 266T424 322Z">
          </path>
          <path id="MJX-4-TEX-I-1D463"
            d="M173 380Q173 405 154 405Q130 405 104 376T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Q21 294 29 316T53 368T97 419T160 441Q202 441 225 417T249 361Q249 344 246 335Q246 329 231 291T200 202T182 113Q182 86 187 69Q200 26 250 26Q287 26 319 60T369 139T398 222T409 277Q409 300 401 317T383 343T365 361T357 383Q357 405 376 424T417 443Q436 443 451 425T467 367Q467 340 455 284T418 159T347 40T241 -11Q177 -11 139 22Q102 54 102 117Q102 148 110 181T151 298Q173 362 173 380Z">
          </path>
          <path id="MJX-4-TEX-I-1D446"
            d="M308 24Q367 24 416 76T466 197Q466 260 414 284Q308 311 278 321T236 341Q176 383 176 462Q176 523 208 573T273 648Q302 673 343 688T407 704H418H425Q521 704 564 640Q565 640 577 653T603 682T623 704Q624 704 627 704T632 705Q645 705 645 698T617 577T585 459T569 456Q549 456 549 465Q549 471 550 475Q550 478 551 494T553 520Q553 554 544 579T526 616T501 641Q465 662 419 662Q362 662 313 616T263 510Q263 480 278 458T319 427Q323 425 389 408T456 390Q490 379 522 342T554 242Q554 216 546 186Q541 164 528 137T492 78T426 18T332 -20Q320 -22 298 -22Q199 -22 144 33L134 44L106 13Q83 -14 78 -18T65 -22Q52 -22 52 -14Q52 -11 110 221Q112 227 130 227H143Q149 221 149 216Q149 214 148 207T144 186T142 153Q144 114 160 87T203 47T255 29T308 24Z">
          </path>
          <path id="MJX-4-TEX-I-1D436"
            d="M50 252Q50 367 117 473T286 641T490 704Q580 704 633 653Q642 643 648 636T656 626L657 623Q660 623 684 649Q691 655 699 663T715 679T725 690L740 705H746Q760 705 760 698Q760 694 728 561Q692 422 692 421Q690 416 687 415T669 413H653Q647 419 647 422Q647 423 648 429T650 449T651 481Q651 552 619 605T510 659Q484 659 454 652T382 628T299 572T226 479Q194 422 175 346T156 222Q156 108 232 58Q280 24 350 24Q441 24 512 92T606 240Q610 253 612 255T628 257Q648 257 648 248Q648 243 647 239Q618 132 523 55T319 -22Q206 -22 128 53T50 252Z">
          </path>
        </defs>
        <g stroke="currentColor" fill="currentColor" strokeWidth="0" transform="scale(1,-1)">
          <g data-mml-node="math">
            <g data-mml-node="mi">
              <use data-c="1D43F" xlinkHref="#MJX-4-TEX-I-1D43F"></use>
            </g>
            <g data-mml-node="mo" transform="translate(958.8,0)">
              <use data-c="3D" xlinkHref="#MJX-4-TEX-N-3D"></use>
            </g>
            <g data-mml-node="mfrac" transform="translate(2014.6,0)">
              <g data-mml-node="mn" transform="translate(220,394) scale(0.707)">
                <use data-c="31" xlinkHref="#MJX-4-TEX-N-31"></use>
              </g>
              <g data-mml-node="mn" transform="translate(220,-345) scale(0.707)">
                <use data-c="32" xlinkHref="#MJX-4-TEX-N-32"></use>
              </g>
              <rect width="553.6" height="60" x="120" y="220"></rect>
            </g>
            <g data-mml-node="mi" transform="translate(2808.1,0)">
              <use data-c="1D70C" xlinkHref="#MJX-4-TEX-I-1D70C"></use>
            </g>
            <g data-mml-node="msup" transform="translate(3325.1,0)">
              <g data-mml-node="mi">
                <use data-c="1D463" xlinkHref="#MJX-4-TEX-I-1D463"></use>
              </g>
              <g data-mml-node="mn" transform="translate(518,363) scale(0.707)">
                <use data-c="32" xlinkHref="#MJX-4-TEX-N-32"></use>
              </g>
            </g>
            <g data-mml-node="mi" transform="translate(4246.7,0)">
              <use data-c="1D446" xlinkHref="#MJX-4-TEX-I-1D446"></use>
            </g>
            <g data-mml-node="msub" transform="translate(4891.7,0)">
              <g data-mml-node="mi">
                <use data-c="1D436" xlinkHref="#MJX-4-TEX-I-1D436"></use>
              </g>
              <g data-mml-node="mi" transform="translate(748,-150) scale(0.707)">
                <use data-c="1D43F" xlinkHref="#MJX-4-TEX-I-1D43F"></use>
              </g>
            </g>
          </g>
        </g>
      </svg></mjx-container>
  </span></p>
<style>
  mjx-container[jax="SVG"] {
    direction: ltr;
  }

  mjx-container[jax="SVG"]>svg {
    overflow: visible;
    min-height: 1px;
    min-width: 1px;
  }

  mjx-container[jax="SVG"]>svg a {
    fill: blue;
    stroke: blue;
  }

  mjx-container[jax="SVG"][display="true"] {
    display: block;
    text-align: center;
    margin: 1em 0;
  }

  mjx-container[jax="SVG"][display="true"][width="full"] {
    display: flex;
  }

  mjx-container[jax="SVG"][justify="left"] {
    text-align: left;
  }

  mjx-container[jax="SVG"][justify="right"] {
    text-align: right;
  }

  g[data-mml-node="merror"]>g {
    fill: red;
    stroke: red;
  }

  g[data-mml-node="merror"]>rect[data-background] {
    fill: yellow;
    stroke: none;
  }

  g[data-mml-node="mtable"]>line[data-line],
  svg[data-table]>g>line[data-line] {
    stroke-width: 70px;
    fill: none;
  }

  g[data-mml-node="mtable"]>rect[data-frame],
  svg[data-table]>g>rect[data-frame] {
    stroke-width: 70px;
    fill: none;
  }

  g[data-mml-node="mtable"]>.mjx-dashed,
  svg[data-table]>g>.mjx-dashed {
    stroke-dasharray: 140;
  }

  g[data-mml-node="mtable"]>.mjx-dotted,
  svg[data-table]>g>.mjx-dotted {
    stroke-linecap: round;
    stroke-dasharray: 0, 140;
  }

  g[data-mml-node="mtable"]>g>svg {
    overflow: visible;
  }

  [jax="SVG"] mjx-tool {
    display: inline-block;
    position: relative;
    width: 0;
    height: 0;
  }

  [jax="SVG"] mjx-tool>mjx-tip {
    position: absolute;
    top: 0;
    left: 0;
  }

  mjx-tool>mjx-tip {
    display: inline-block;
    padding: .2em;
    border: 1px solid #888;
    font-size: 70%;
    background-color: #F8F8F8;
    color: black;
    box-shadow: 2px 2px 5px #AAAAAA;
  }

  g[data-mml-node="maction"][data-toggle] {
    cursor: pointer;
  }

  mjx-status {
    display: block;
    position: fixed;
    left: 1em;
    bottom: 1em;
    min-width: 25%;
    padding: .2em .4em;
    border: 1px solid #888;
    font-size: 90%;
    background-color: #F8F8F8;
    color: black;
  }

  foreignObject[data-mjx-xml] {
    font-family: initial;
    line-height: normal;
    overflow: visible;
  }

  mjx-container[jax="SVG"] path[data-c],
  mjx-container[jax="SVG"] use[data-c] {
    stroke-width: 3;
  }
</style>

@Enteleform
Copy link
Contributor Author

Enteleform commented Jan 13, 2022

Also just noticed this:

image

It seems that the base URL for fonts has changed from

https://cdn.jsdelivr.net/npm/mathjax@3/components/output/chtml/fonts/woff-v2/

to

https://cdn.jsdelivr.net/npm/mathjax@3/es5/output/chtml/fonts/woff-v2/

@wooorm
Copy link
Member

wooorm commented Jan 13, 2022

Interested in working on a PR for the URL change?
For SVG, yes, more info would be useful. See https://github.com/remarkjs/.github/blob/main/support.md on how to help us help you!

@Enteleform
Copy link
Contributor Author

Enteleform commented Jan 13, 2022

Interested in working on a PR for the URL change?

Just forked the repo but didn't find any jsdelivr references other than in a few readme files.

image

 

For SVG, yes, more info would be useful.

Here's a minimal repro:
https://codesandbox.io/s/mathjax-svg-render-issue-u4h0h

image

@wooorm
Copy link
Member

wooorm commented Jan 13, 2022

@Enteleform
Copy link
Contributor Author

Enteleform commented Jan 13, 2022

  • I meant a PR to the docs, indeed.

Oh whoops I forgot that the docs instruct you to add that URL to your config & was thinking there was a hardcoded URL somewhere in the codebase 😅.

Just submitted a PR.

 

  • Your issue is not reproducible without Vite or Solid (here’s a start with just xdm and react). I am assuming it’s Solid.js.

Hmm weird, so both rehype-katex & rehype-mathjax/chtml work fine with Solid, not sure what's going on there. Also have used other SVG loaders, like unplugin-icons, without issue.

However, I did notice that even with the repro starter you sent me, the results aren't matching up between svg & chtml:

Left: Solid + CHTML
Right: React + SVG
image

wooorm pushed a commit that referenced this issue Jan 14, 2022
Related-to GH-72.
Closes GH-73.

Reviewed-by: Titus Wormer <tituswormer@gmail.com>
@wooorm
Copy link
Member

wooorm commented Jan 14, 2022

not sure what's going on there.

I’m assuming Solid + JSX + SVG.

the results aren't matching up between svg & chtml:

One is a plain text file. The other is a backticked string in JavaScript. JavaScript eats the \ escapes. You must escape the backslashes for JavaScript. I think that’s what you mean?

@Enteleform
Copy link
Contributor Author

Ah yeah, that was the issue. Ok I'll try diffing that result against the one from Solid & see if anybody @ their Discord might know what's going on if I can't figure it out. Thanks for the assistance!

@mdynnl
Copy link

mdynnl commented Jan 15, 2022

😁 Chiming in. svg didn't work because hastscript transforms xlink:href attributes or any other in the iri:attr form to xlinkHref which can be seen in rendered-html from #72 (comment)
hastscript output can't be reverted back to the original html(a hunch).
I guess vdom libraries can handle this fine probably via aliasing xlinkHref to iri form(not familiar with the internals but I hope it's kinda like that). For a compiled template approach which solid takes, these will get rendered as is and the attributes won't get set correctly. That said, the aliasing can be done with solid too via jsx runtime which has downsides such as losing full reactivity which probably suffices @Enteleform 's use case.

Another problem with jsx output is
<_components.custom-element> and </_components."custom-element"> which prevents taking compiled approach. Opinions on how to solve it may vary. Nothing urgent. Just reporting 🤗.

If mathjax doesn't use a custom element name and xlink:href (obsolete by href), these issues wouldn't come up.

@wooorm
Copy link
Member

wooorm commented Jan 15, 2022

Hi Nyi Nyi!

svg didn't work because […] xlink:href attributes […] form to xlinkHref which can be seen in rendered-html from 72 (comment)

Yes, thanks for finding the precise cause.
To add, this is not so much about hastscript though. This is about how React expects JSX to be authored: https://stackoverflow.com/questions/26815738/svg-use-tag-and-reactjs.
This is why I pointed to Solid + JSX + SVG as the root cause.

For a compiled template approach which solid takes, these will get rendered as is and the attributes won't get set correctly.

Similar to a VDOM _jsx runtime, the SolidJS runtime could also handle attributes. Why not? How would it be problematic for reactivity?

In this case high1/solid-jsx could map the fields that React expects to the fields that HTML expects (property-information might help).

Another problem with jsx output is
<_components.custom-element> and </_components."custom-element"> which prevents taking compiled approach.

Can you expand on this point? JSX supports the first fine (tested with xdm: it works). The last is not JSX. I don’t think xdm or MDX need to change to support that?

@mdynnl
Copy link

mdynnl commented Jan 15, 2022

After digging more, I've come to know there are reason why things are the way things are. Don't have any opinion atm. Pretty overwhelmed by standards but here's a sorta working example https://codesandbox.io/s/mathjax-svg-render-issue-forked-pk07y?file=/vite.config.ts
I was working on this and the commented popped up so continuing

Similar to a VDOM _jsx runtime, the SolidJS runtime could also handle attributes. Why not? How would it be problematic for reactivity?

Yes, which I did there. The reactivity is kinda limited with jsx-runtime approach. Roughly, Solid needs to analyze jsx and transform the js parts to work with its reactivity system and jsx to templates via a babel plugin. And we found a better way which was to use {jsx:true, providerImportSource: ...}. Reactivity's solved but solid's web runtime aims to be as closer as possible to the native dom behavior. Hence, mdx being able to output the jsx as close as html(in native dom format) via an option or so is really desirable.

Can you expand on this point? JSX supports the first fine (tested with xdm: it works). The last is not JSX. I don’t think xdm or MDX need to change to support that?

Yes they aren't and is the jsx output of mdx|xdm with rehype-mathjax/svg coming from mathjax's use of mjx-container tag. I don't have opinion about this as said on top. This is pretty much on mathjax.

@Enteleform
Copy link
Contributor Author

Can you expand on this point? JSX supports the first fine (tested with xdm: it works). The last is not JSX. I don’t think xdm or MDX need to change to support that?

Hey so we've been discussing this over @ Discord/SolidJS/help, and it seems that solid-jsx has been succeeded by solid-mdx.

Before making the switch, I ran a diff against updated versions of the initial repros I submitted:

Based on the diff, it seems like the generated SVG code is invalid due to:

  • attributes are camelCased instead of kebab-cased
  • : characters are removed, as in xmlns:xlink >> xmlnsXlink
  • style attribute is completely removed

The Solid version also ends up with class instead of classname, although I'm not sure that that's contributing to the issue in any way, since class is a valid attribute in Solid.

 
After switching to solid-mdx, it started erroring out @ build time. Here's the transformed MDX file, after it's been run through xdm + solid-mdx, and a CodeSandbox Repro with the updated config.

It's currently throwing this error:
image
image

which seems like it could be related to the fix that was implemented for the original topic of this issue?

@wooorm
Copy link
Member

wooorm commented Jan 15, 2022

Hence, mdx being able to output the jsx as close as html(in native dom format) via an option or so is really desirable.

Why not use markdown? Markdown outputs HTML.
The goal of MDX is to ditch HTML in favor of JS(X).

solid-mdx

This package has no documentation and is only a few days old.
If solid-mdx provides a proper automatic JSX runtime that works with MDX, then it shouldn’t be called solid-mdx: it should be called solid-jsx.


which seems like it could be related to the fix that was implemented for the original topic of this issue?

Yes. Want to work on a PR?

@Enteleform
Copy link
Contributor Author

Yes. Want to work on a PR?

This is a bit lower level stuff than I'm used to working on, but could take a shot at it perhaps.

I managed to get it rendering properly with a few replacements run after the initial transform:

image

{from:`xmlnsXlink=`,                       to:`xmlns:xlink=`                      },
{from:`xlinkHref=`,                        to:`xlink:href=`                       },
{from:`className=`,                        to:`class=`                            },
{from:`"mjx-container": "mjx-container",`, to:`"mjxcontainer": "span",`           },
{from:`.mjx-container class="MathJax`,     to:`.span class="MathJax MJX_Container`},
{from:`."mjx-container" class="MathJax`,   to:`.span class="MathJax MJX_Container`},
{from:`</_components.mjx-container>`,      to:`</_components.span>`               },
{from:`</_components."mjx-container">`,    to:`</_components.span>`               },
{from:`mjx-container`,                     to:`.MJX_Container`                    },

Do you think there's a way it could be set up to where it would work for both React & Solid?

@wooorm
Copy link
Member

wooorm commented Jan 15, 2022

  • The form of attributes is a solid/solid-jsx/solid-mdx problem. It is not a bug in xdm or MDX.
  • </_components.mjx-container> and mjx-container are not bugs in xdm or MDX either. Those are valid JSX.
  • </_components."mjx-container"> is a bug in xdm and MDX. I was hoping you might be interested in working on a PR for that.

@Enteleform
Copy link
Contributor Author

Enteleform commented Jan 15, 2022

  • The form of attributes is a solid/solid-jsx/solid-mdx problem. It is not a bug in xdm or MDX.
  • </_components."mjx-container"> is a bug in xdm and MDX. I was hoping you might be interested in working on a PR for that.

Gotcha, I'm wondering if there are any steps that could be taken to facilitate interop between mdx-js/xdm and libraries like Solid that utilize JSX in a different way than React. Perhaps this could be accomplished with additional config options that affect the transformation process. Is something you'd welcome as a PR?

If so, I could be open to working on this and could also forward the info to the Solid community; although as of right now, I don't have much AST-manipulation experience so it would definitely require some time + research before I could personally contribute anything of value. I'm open to it though!

@wooorm
Copy link
Member

wooorm commented Jan 15, 2022

I'm wondering if there are any steps that could be taken to facilitate interop between mdx-js/xdm and libraries like Solid that utilize JSX in a different way than React.

Yes there is. The glue is called solid-jsx. That’s the bridge between JSX and frameworks. It has bugs and it should be fixed. Please see #72 (comment).

@Enteleform
Copy link
Contributor Author

Yes there is. The glue is called solid-jsx. That’s the bridge between JSX and frameworks. It has bugs and it should be fixed. Please see #72 (comment).

Ok I'll look into this further when I get a chance and dig into the source code of all of the involved libraries. It's tough to tell what's going on without prior experience with this ecosystem & AST work, and also to know where this needs to be addressed because both sides are claiming that the other is where the issue lies.

I appreciate your time & explanations!

@mdynnl
Copy link

mdynnl commented Jan 16, 2022

</_components.mjx-container> and mjx-container are not bugs in xdm or MDX either. Those are valid JSX.

Does MDX choose to support it?
https://codesandbox.io/s/sharp-browser-ebt2t?file=/src/index.js

</_components."mjx-container"> is a bug in xdm and MDX. I was hoping you might be interested in working on a PR for that.

I found it but holding because of the above.

I can work on both.

@wooorm
Copy link
Member

wooorm commented Jan 16, 2022

Ok I'll look into this further when I get a chance and dig into the source code of all of the involved libraries.

I believe I‘ve mentioned a few times now that you can use property-information inside solid-jsx to solve this.
To clarify, solid-jsx takes properties here: https://github.com/high1/solid-jsx/blob/e0264f9d4fbd67a46b8b8f8d16e867393fd0bd3f/src/jsx-runtime.tsx#L8.
You can add code there to turn className into class, and all the other transformations where the React form differs from the SolidJS form.
You can perhaps also use property-information or similar libraries.


Does MDX choose to support it?

The standard defines it as such: https://facebook.github.io/jsx/. (observer: JSXMemberExpression, which references JSXIdentifier, which allows -. The “normal” Identifier and IdentifierPart, from ECMAScript (example) do not allow -).

Other implementations match this behavior.

wooorm added a commit to wooorm/xdm that referenced this issue Jan 18, 2022
Related to: ddcebdb.
Related to: remarkjs/remark-math#72.
Closes GH-106.

Co-authored-by: Titus Wormer <tituswormer@gmail.com>
wooorm added a commit to mdx-js/mdx that referenced this issue Jan 25, 2022
wooorm added a commit to mdx-js/mdx that referenced this issue Jan 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👀 no/external This makes more sense somewhere else 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

3 participants