From 7ac3d4bdd8696ce132691db7d75d10a6ceab28f3 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Mon, 15 Apr 2024 13:01:42 -0400 Subject: [PATCH 1/2] Upgrade node:20-alpine (20.12.2) (#50141) --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8768f6428c9d..e716e9e62ce3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ # -------------------------------------------------------------------------------- # To update the sha, run `docker pull node:$VERSION-alpine` # look for something like: `Digest: sha256:0123456789abcdef` -FROM node:20-alpine@sha256:7e227295e96f5b00aa79555ae166f50610940d888fc2e321cf36304cbd17d7d6 as base +FROM node:20-alpine@sha256:ec0c413b1d84f3f7f67ec986ba885930c57b5318d2eb3abc6960ee05d4f2eb28 as base # This directory is owned by the node user ARG APP_HOME=/home/node/app From 84a523f52b0ef0bf92a908c9551b8fc9d8250e1c Mon Sep 17 00:00:00 2001 From: Kevin Heis Date: Mon, 15 Apr 2024 10:14:49 -0700 Subject: [PATCH 2/2] Update reusable data to handle blockquote (#50145) --- src/content-render/liquid/data.js | 80 +++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 26 deletions(-) diff --git a/src/content-render/liquid/data.js b/src/content-render/liquid/data.js index a819fe5b4b97..afeb9ec5c0dc 100644 --- a/src/content-render/liquid/data.js +++ b/src/content-render/liquid/data.js @@ -28,34 +28,62 @@ export default { } return } + text = text.trim() - // Any time what we're about to replace in here has more than one line, - // if the use of `{% data ... %}` was itself indented, from the left, - // keep *that* indentation, in replaced output, for every line. - // - // For example: - // - // 1. Bullet point - // {% data variables.foo.bar %} - // - // In this example, the `{% data ...` starts with 3 whitespaces - // (based on the `1. Bull...` in the example). So put 3 whitespaces - // in front every line of the output. - if (text.split('\n').length > 0) { - const { input, begin } = this.tagToken - let i = 1 - while (input.charAt(begin - i) === ' ') { - i++ // this goes one character "to the left" - } - const goBack = input.slice(begin - i, begin) - if (goBack.charAt(0) === '\n' && goBack.length > 1) { - const numSpaces = goBack.length - 1 - text = text.trim().replace(/^/gm, ' '.repeat(numSpaces)).trim() - } - } else { - text = text.trim() - } + text = handleIndent(this.tagToken, text) + text = handleBlockquote(this.tagToken, text) return this.liquid.parseAndRender(text, scope.environments) }, } + +function handleIndent(tagToken, text) { + // Any time what we're about to replace in here has more than one line, + // if the use of `{% data ... %}` was itself indented, from the left, + // keep *that* indentation, in replaced output, for every line. + // + // For example: + // + // 1. Bullet point + // {% data variables.foo.bar %} + // + // In this example, the `{% data ...` starts with 3 whitespaces + // (based on the `1. Bull...` in the example). So put 3 whitespaces + // in front every line of the output. + if (text.split('\n').length === 0) return text + const { input, begin } = tagToken + let i = 1 + while (input.charAt(begin - i) === ' ') { + i++ // this goes one character "to the left" + } + const goBack = input.slice(begin - i, begin) + if (goBack.charAt(0) === '\n' && goBack.length > 1) { + const numSpaces = goBack.length - 1 + return text.replace(/^/gm, ' '.repeat(numSpaces)).trim() + } + return text +} + +// When a reusable has multiple lines, and the input line is a blockquote, +// keep the blockquote character on every successive line. +const blockquoteRegexp = /^\n?([ \t]*>[ \t]?)/ +function handleBlockquote(tagToken, text) { + // If the text isn't multiline, skip + if (text.split('\n').length <= 1) return text + + // If the line with the liquid tag starts with a blockquote... + const { input, content } = tagToken + const inputLine = input.split('\n').find((line) => line.includes(content)) + if (!blockquoteRegexp.test(inputLine)) return text + + // Keep the character on successive lines + const start = inputLine.match(blockquoteRegexp)[0] + return text + .split('\n') + .map((line, i) => { + if (i === 0) return line + if (blockquoteRegexp.test(line)) return line + return start + line.trim() + }) + .join('\n') +}