From 82c8247ac8dfda1dd7aa4add629ede34f6cdf5f1 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Fri, 17 Feb 2023 01:54:19 +0800 Subject: [PATCH] Fix infinite loop bug!! --- src/utils/enhance-content.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/utils/enhance-content.js b/src/utils/enhance-content.js index 33d2c6d5..fe30f50f 100644 --- a/src/utils/enhance-content.js +++ b/src/utils/enhance-content.js @@ -51,8 +51,9 @@ function enhanceContent(content, opts = {}) { codeBlocks.forEach((block) => { const nextParagraphs = [block]; let hasCodeBlock = false; - do { - const next = block.nextElementSibling; + let currentBlock = block; + while (currentBlock.nextElementSibling) { + const next = currentBlock.nextElementSibling; if (next && next.tagName === 'P') { if (/```$/g.test(next.innerText)) { nextParagraphs.push(next); @@ -64,7 +65,8 @@ function enhanceContent(content, opts = {}) { } else { break; } - } while (true); + currentBlock = next; + } if (hasCodeBlock) { const pre = document.createElement('pre'); nextParagraphs.forEach((p) => {