From ab458e7143f7256fa37b0478aa1c87cb7a500ff3 Mon Sep 17 00:00:00 2001 From: Marcos Pereira Date: Wed, 15 May 2024 14:06:40 -0400 Subject: [PATCH] feat: Add inlineSlyeNonce configuration (#2542) --- src/htmx.d.ts | 1 + src/htmx.js | 9 ++++++++- www/content/api.md | 1 + www/content/docs.md | 1 + www/content/reference.md | 1 + 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/htmx.d.ts b/src/htmx.d.ts index 36ee4ca4..3775459f 100644 --- a/src/htmx.d.ts +++ b/src/htmx.d.ts @@ -36,6 +36,7 @@ declare namespace htmx { const allowEval: boolean; const allowScriptTags: boolean; const inlineScriptNonce: string; + const inlineStyleNonce: string; const attributesToSettle: string[]; const withCredentials: boolean; const timeout: number; diff --git a/src/htmx.js b/src/htmx.js index 34fb33f3..46a7fb86 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -164,6 +164,12 @@ var htmx = (function() { * @default '' */ inlineScriptNonce: '', + /** + * If set, the nonce will be added to inline styles. + * @type string + * @default '' + */ + inlineStyleNonce: '', /** * The attributes to settle during the settling phase. * @type string[] @@ -4866,8 +4872,9 @@ var htmx = (function() { function insertIndicatorStyles() { if (htmx.config.includeIndicatorStyles !== false) { + const nonceAttribute = htmx.config.inlineStyleNonce ? ` nonce="${htmx.config.inlineStyleNonce}"` : '' getDocument().head.insertAdjacentHTML('beforeend', - '