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 'nonce' attribute to inline stylesheets #672

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

christianp
Copy link
Contributor

@christianp christianp commented Mar 30, 2021

The output options now has a property 'nonce', which is a string to use as the value for a 'nonce' attribute on <style> tags created by the output jax. If it's not given, no 'nonce' attribute is added.

This fixes mathjax/MathJax#2665

Here's a tiny page to test:

<!doctype html>
<html>
    <head>
        <script>
            window.MathJax = {
                chtml: {
                    nonce: 'hello'
                },
            };
        </script>
        <script src="es5/tex-chtml.js"></script>
    </head>
    <body>
        <p>This is \(x^2 + \int y\)</p>
    </body>
</html>

The style.MJX-CHTML-styles tag has an attribute nonce="hello".

The output options now has a property 'nonce', which is a string to use
as the value for a 'nonce' attribute on <style> tags created by the
output jax.
If it's not given, no 'nonce' attribute is added.

fixes #2665
@christianp christianp requested a review from dpvc March 30, 2021 09:45
@christianp
Copy link
Contributor Author

The context menu also creates stylesheets, but it uses its own methods rather than the ones in OutputJax. I'm prepared to make the same changes to the mj-context-menu package, but where is the right place to pass it the nonce value? Is it possible to access the top-level options object from within the output jax and the context menu's constructors?

@dpvc
Copy link
Member

dpvc commented Apr 1, 2021

I don't think you will be able to get the menu to work, as there are lots of dynamically changing styles, from the position of the menu initially, to the placement of submenus, and other things that are not mediated by classes. The creation of stylesheets is done here:

https://github.com/zorkow/context-menu/blob/8ddd26a41f834cd23b9bb20737dfae5fa9b05eb4/ts/css_util.ts#L274-L287

but this is inside a namespace, and is not exported, so it is not something you could get your hands on easily.

I think you may have to go without the menu.

@zorkow
Copy link
Member

zorkow commented Apr 8, 2021

The unorthodox use of namespaces are an artefact of the lack of string enum types in Typescript ~v2.X and my trying to achieve similar type checking behaviour as in closure. This will need an overhaul one of these days.

@dpvc dpvc force-pushed the develop branch 3 times, most recently from b77df61 to 1f851dd Compare April 25, 2024 16:21
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