From 4f91ee5bb770c11435e501dceb7db62991ce66af Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 31 May 2024 21:02:23 -0300 Subject: html: fix chunkwrap generation error See issue #484. Also see #code-quarantine: https://discord.com/channels/749042497610842152/854020929113423924/1246242946525691956 --- src/util/html.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/util/html.js b/src/util/html.js index 9e07f9ba..bd9f4eb7 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -658,28 +658,25 @@ export class Tag { : null); if (content) { - if (itemIncludesChunkwrapSplit) { - if (!seenChunkwrapSplitter) { - // The first time we see a chunkwrap splitter, backtrack and wrap - // the content *so far* in a chunk. - content = `` + content; - } - - // Close the existing chunk. We'll add the new chunks after the - // (normal) joiner. - content += ``; + if (itemIncludesChunkwrapSplit && !seenChunkwrapSplitter) { + // The first time we see a chunkwrap splitter, backtrack and wrap + // the content *so far* in a chunk. This will be treated just like + // any other open chunkwrap, and closed after the first chunk of + // this item! (That means the existing content is part of the same + // chunk as the first chunk included in this content, which makes + // sense, because that first chink is really just more text that + // precedes the first split.) + content = `` + content; } content += joiner; - } else { + } else if (itemIncludesChunkwrapSplit) { // We've encountered a chunkwrap split before any other content. // This means there's no content to wrap, no existing chunkwrap // to close, and no reason to add a joiner, but we *do* need to // enter a chunkwrap wrapper *now*, so the first chunk of this // item will be properly wrapped. - if (itemIncludesChunkwrapSplit) { - content = ``; - } + content = ``; } if (itemIncludesChunkwrapSplit) { @@ -700,6 +697,10 @@ export class Tag { if (itemIncludesChunkwrapSplit) { for (const [index, chunk] of chunkwrapChunks.entries()) { if (index === 0) { + // The first chunk isn't actually a chunk all on its own, it's + // text that should be appended to the previous chunk. We will + // close this chunk as the first appended content as we process + // the next chunk. content += chunk; } else { const whitespace = chunk.match(/^\s+/) ?? ''; -- cgit 1.3.0-6-gf8a5