From e1095324104d3b6e131d50a4ee8d2d1ee4061327 Mon Sep 17 00:00:00 2001 From: BaskarMitrah Date: Wed, 1 Apr 2026 18:58:34 +0530 Subject: [PATCH 1/3] fix : code line issue --- hlx_statics/components/code.js | 13 +++++++++++-- hlx_statics/scripts/lib-adobeio.js | 3 +++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/hlx_statics/components/code.js b/hlx_statics/components/code.js index 8d1c2915..cdc6877a 100644 --- a/hlx_statics/components/code.js +++ b/hlx_statics/components/code.js @@ -129,8 +129,15 @@ function applyDataAttributesFromCodeClasses(pre, code) { }); } +/** Same idea as Prism’s /\n(?!$)/: at least one line break that is not only a trailing newline. */ +function codeTextIsMultiLine(text) { + const s = text ?? ''; + const i = s.indexOf('\n'); + return i !== -1 && i < s.length - 1; +} + export default function decoratePreformattedCode(block) { - const pre = block.querySelector('pre'); + const pre = block.querySelector('pre') || (block.tagName === 'PRE' && block) || null const code = block.querySelector('code'); applyDataAttributesFromCodeClasses(pre, code); @@ -161,7 +168,9 @@ export default function decoratePreformattedCode(block) { code && processClasses(code); } - if (pre?.classList.contains("disableLineNumbers")) { + // Match Gatsby/production: gutter only when there is more than one line. + const isMultiLine = code && codeTextIsMultiLine(code.textContent); + if (pre?.classList.contains('disableLineNumbers') || !isMultiLine) { pre?.classList.add('no-line-numbers'); } else { diff --git a/hlx_statics/scripts/lib-adobeio.js b/hlx_statics/scripts/lib-adobeio.js index 51fbc8a9..ed223019 100644 --- a/hlx_statics/scripts/lib-adobeio.js +++ b/hlx_statics/scripts/lib-adobeio.js @@ -216,6 +216,9 @@ export function decorateInlineCodes(element) { if (up.tagName !== 'PRE') { code.classList.add('inline-code'); } + else { + decoratePreformattedCode(up); + } }); } From 5d28511548d54781dbea5881b33cab8969a3d44a Mon Sep 17 00:00:00 2001 From: BaskarMitrah Date: Wed, 1 Apr 2026 20:54:44 +0530 Subject: [PATCH 2/3] changed in inlinealert --- hlx_statics/blocks/inlinealert/inlinealert.js | 7 ++++++- hlx_statics/components/code.js | 11 +---------- hlx_statics/scripts/lib-adobeio.js | 3 --- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/hlx_statics/blocks/inlinealert/inlinealert.js b/hlx_statics/blocks/inlinealert/inlinealert.js index 23149c59..48b20b6e 100644 --- a/hlx_statics/blocks/inlinealert/inlinealert.js +++ b/hlx_statics/blocks/inlinealert/inlinealert.js @@ -1,3 +1,4 @@ +import decoratePreformattedCode from '../../components/code.js'; import { createTag, } from '../../scripts/lib-adobeio.js'; @@ -42,7 +43,7 @@ export function getVariant(classList) { export default async function decorate(block) { block.classList.add('spectrum-InLineAlert'); - const slots = block?.getAttribute('data-slots')?.split(','); + const slots = block?.getAttribute('data-slots')?.split(',').map(slot => slot.trim()); const classVariant = getVariant(block.classList); block.classList.add(classVariant.class); @@ -51,6 +52,10 @@ export default async function decorate(block) { // need to wrap content into p block.querySelectorAll(':scope > div > div').forEach((div, i) =>{ const className = slots?.[i] === 'heading' ? 'spectrum-InLineAlert-header' : 'spectrum-InLineAlert-content'; + const isCodeSlot = slots?.[i] === 'code'; + if (isCodeSlot) { + decoratePreformattedCode(div); + } const inlineP = createTag('p', { class: className }); inlineP.innerHTML = div.innerHTML; block.appendChild(inlineP); diff --git a/hlx_statics/components/code.js b/hlx_statics/components/code.js index cdc6877a..d62e7cd5 100644 --- a/hlx_statics/components/code.js +++ b/hlx_statics/components/code.js @@ -129,13 +129,6 @@ function applyDataAttributesFromCodeClasses(pre, code) { }); } -/** Same idea as Prism’s /\n(?!$)/: at least one line break that is not only a trailing newline. */ -function codeTextIsMultiLine(text) { - const s = text ?? ''; - const i = s.indexOf('\n'); - return i !== -1 && i < s.length - 1; -} - export default function decoratePreformattedCode(block) { const pre = block.querySelector('pre') || (block.tagName === 'PRE' && block) || null const code = block.querySelector('code'); @@ -168,9 +161,7 @@ export default function decoratePreformattedCode(block) { code && processClasses(code); } - // Match Gatsby/production: gutter only when there is more than one line. - const isMultiLine = code && codeTextIsMultiLine(code.textContent); - if (pre?.classList.contains('disableLineNumbers') || !isMultiLine) { + if (pre?.classList.contains('disableLineNumbers')) { pre?.classList.add('no-line-numbers'); } else { diff --git a/hlx_statics/scripts/lib-adobeio.js b/hlx_statics/scripts/lib-adobeio.js index ed223019..51fbc8a9 100644 --- a/hlx_statics/scripts/lib-adobeio.js +++ b/hlx_statics/scripts/lib-adobeio.js @@ -216,9 +216,6 @@ export function decorateInlineCodes(element) { if (up.tagName !== 'PRE') { code.classList.add('inline-code'); } - else { - decoratePreformattedCode(up); - } }); } From 68456b02178a12334b0b38833e37e907678e2a1a Mon Sep 17 00:00:00 2001 From: BaskarMitrah Date: Wed, 1 Apr 2026 20:56:55 +0530 Subject: [PATCH 3/3] added semicolon at end --- hlx_statics/components/code.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hlx_statics/components/code.js b/hlx_statics/components/code.js index d62e7cd5..9033e010 100644 --- a/hlx_statics/components/code.js +++ b/hlx_statics/components/code.js @@ -130,7 +130,7 @@ function applyDataAttributesFromCodeClasses(pre, code) { } export default function decoratePreformattedCode(block) { - const pre = block.querySelector('pre') || (block.tagName === 'PRE' && block) || null + const pre = block.querySelector('pre') || (block.tagName === 'PRE' && block) || null; const code = block.querySelector('code'); applyDataAttributesFromCodeClasses(pre, code);