add support for CSP nonces in createStyleTag

This commit is contained in:
Felix Klein
2022-03-07 16:35:06 +01:00
committed by Dominik
parent 413a923d57
commit ccc37d5f24
4 changed files with 24 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
export function createStyleTag(style: string): HTMLStyleElement {
export function createStyleTag(style: string, nonce?: string): HTMLStyleElement {
const tipTapStyleTag = (<HTMLStyleElement>document.querySelector('style[data-tiptap-style]'))
if (tipTapStyleTag !== null) {
@@ -7,6 +7,10 @@ export function createStyleTag(style: string): HTMLStyleElement {
const styleNode = document.createElement('style')
if (nonce) {
styleNode.setAttribute('nonce', nonce)
}
styleNode.setAttribute('data-tiptap-style', '')
styleNode.innerHTML = style
document.getElementsByTagName('head')[0].appendChild(styleNode)