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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions ts/output/common/OutputJax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ export abstract class CommonOutputJax<
displayIndent: '0', // default for indentshift when set to 'auto'
wrapperFactory: null, // The wrapper factory to use
font: null, // The FontData object to use
cssStyles: null // The CssStyles object to use
cssStyles: null, // The CssStyles object to use
nonce: null // The nonce value to apply to style tags created by MathJax
};

/**
Expand Down Expand Up @@ -464,13 +465,28 @@ export abstract class CommonOutputJax<
// Get the font styles
//
this.cssStyles.addStyles(this.font.styles);
//
// Set up the properties for the stylesheet
//
const def : {id: string, nonce?: string} = {id: 'MJX-styles'};
const nonce = this.getNonce();
if (nonce) {
def['nonce'] = nonce;
}
//
// Create the stylesheet for the CSS
//
const sheet = this.html('style', {id: 'MJX-styles'}, [this.text('\n' + this.cssStyles.cssText + '\n')]);
const sheet = this.html('style', def, [this.text('\n' + this.cssStyles.cssText + '\n')]);
return sheet as N;
}

/**
* @return {string} The nonce value to apply to stylesheets created by MathJax
*/
protected getNonce(): string|null {
return this.options.nonce;
}

/**
* @param {any} CLASS The Wrapper class whose styles are to be added
*/
Expand Down