Update a rule.

This commit is contained in:
liding 2024-08-07 18:01:36 +08:00
parent 5d4d388fe8
commit c323698b2a

View File

@ -9,10 +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 <strong> or <em>, add a heading space to this
// line.
// 6. If a line ends with </strong> or </em>, add a tailing space to this
// line.
// 5. If a line starts with <strong> or <em> or <a>, add a heading space to
// this line.
// 6. If a line ends with </strong> or </em> or </a>, 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];
@ -47,11 +47,11 @@ for (let i = 1; i < arr.length; i++) {
arr[i] += " ";
}
// rule 5
if (arr[i].match(/^(<em>|<strong>)/) !== null){
if (arr[i].match(/^(<em>|<strong>|<a>)/) !== null){
arr[i] = " " + arr[i];
}
// rule 6
if (arr[i].match(/(<\/em>|<\/strong>)$/) !== null){
if (arr[i].match(/(<\/em>|<\/strong>|<\/a>)$/) !== null){
arr[i] = arr[i] + " ";
}
// -------- combine lines