From 5d4d388fe81b90afdfaa533b233c2d9e5d1a24a8 Mon Sep 17 00:00:00 2001 From: liding Date: Tue, 6 Aug 2024 11:00:42 +0800 Subject: [PATCH] Add new processing rule and improve comments. --- .../article/article_body/ArticleBody.astro | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/components/article/article_body/ArticleBody.astro b/src/components/article/article_body/ArticleBody.astro index 392ecc5..93af240 100644 --- a/src/components/article/article_body/ArticleBody.astro +++ b/src/components/article/article_body/ArticleBody.astro @@ -9,6 +9,10 @@ const html = await Astro.slots.render("default"); // 3. If a line ends without [a-zA-Z] and its next line starts with [a-zA-Z], // add a heading space to the next line. // 4. If a line does not start in ASCII chars, join it to its previous line. +// 5. If a line starts with or , add a heading space to this +// line. +// 6. If a line ends with or , add a tailing space to this +// line. // This is important in using one newline character to wrap Chinese. const arr = html.split("\n"); let articleHTMLFinal = arr[0]; @@ -16,6 +20,7 @@ let remainIntactArea = false; // The first line of the HTML string is a table-of-content head recognized by // remark-toc so it can be ignored. for (let i = 1; i < arr.length; i++) { + // rule 1 // Check if the current line belongs to some block area. if (arr[i].match(/^(|)/) !== null){ + arr[i] = " " + arr[i]; + } + // rule 6 + if (arr[i].match(/(<\/em>|<\/strong>)$/) !== null){ + arr[i] = arr[i] + " "; + } // -------- combine lines + // rule 4 if ( // ( // If the first character is not ascii character,