mathjax / mathjax/MathJax

Could outputs use document.adoptedStyleSheets?

Open
#3,499 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Code Example Feature Request v4
Dominant language
JavaScript
Stars
10.9k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

Motivation: I recently changed Numbas to put all the content inside a custom <numbas-exam> element, to enable us to have several independent Numbas exams in the same page. This has revealed a lot of libraries that assume they're not operating in a shadow DOM, including MathJax.

There's a new adoptedStyleSheets property of documents, whose purpose is to let you share stylesheets between the main document and shadow DOMs. It only works with CSSStyleSheet objects created in JavaScript, as opposed to stylesheets parsed from <style> tags.

Could MathJax make its stylesheets this way, so they can be shared with custom element shadow DOMs? What I'd like to do is something like

custom_element.shadowRoot.adoptedStyleSheets = MathJax.getDocument().output.getStyleSheets()

where CommonOutputJax.getStyleSheets is a method that returns a list of any stylesheets belonging to the output JAX.

The immediate reason I can see this being hard is that you'd have to break the API to work with CSSStyleSheet objects instead of <style> elements. But even if the output JAX could have both a <style> element and a mirrored CSSStyleSheet object, that would be helpful.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting the CommonOutputJax stylesheet handling and the MathJax.getDocument().output API described in the issue. Determine how output stylesheets can expose CSSStyleSheet objects for shadow roots while preserving existing style-element behavior; done means callers can share the output JAX styles through adoptedStyleSheets.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.