Преглед изворни кода

Perfect the logic of case 1.1.x

Yu QX пре 9 месеци
родитељ
комит
4483fa95b8
1 измењених фајлова са 5 додато и 9 уклоњено
  1. 5 9
      src/lib/utils/processResponseContent/special-cases.ts

+ 5 - 9
src/lib/utils/processResponseContent/special-cases.ts

@@ -15,8 +15,6 @@ export const specialCases = (src: string): string => {
 	const processedLines = lines.map((line) => {
 	const processedLines = lines.map((line) => {
 		// 1. 中文 (Chinese, CN)
 		// 1. 中文 (Chinese, CN)
 		if (/[\u4e00-\u9fa5]/.test(line)) {
 		if (/[\u4e00-\u9fa5]/.test(line)) {
-			// Only execute if there are Chinese characters.
-
 			// 1.1. Problems caused by Chinese parentheses
 			// 1.1. Problems caused by Chinese parentheses
 			/* Discription:
 			/* Discription:
 			 *   When `*` has Chinese parentheses on the inside, markdown parser ignore bold or italic style.
 			 *   When `*` has Chinese parentheses on the inside, markdown parser ignore bold or italic style.
@@ -32,8 +30,6 @@ export const specialCases = (src: string): string => {
 			 */
 			 */
 
 
 			if (line.includes('*')) {
 			if (line.includes('*')) {
-				// Only execute if `*` is found in line.
-
 				// 1.1.1. Handle **bold** with Chinese parentheses
 				// 1.1.1. Handle **bold** with Chinese parentheses
 				line = processCN_01(line, '**', '(', ')');
 				line = processCN_01(line, '**', '(', ')');
 				// 1.1.2. Handle *italic* with Chinese parentheses
 				// 1.1.2. Handle *italic* with Chinese parentheses
@@ -71,16 +67,16 @@ function processCN_01(
 ): string {
 ): string {
 	const escapedSymbol = escapeRegExp(symbol);
 	const escapedSymbol = escapeRegExp(symbol);
 	const regex = new RegExp(
 	const regex = new RegExp(
-		`(.*?)(?<!${escapedSymbol})(${escapedSymbol})([^${escapedSymbol}]+)(${escapedSymbol})(?!${escapedSymbol})(.*?)`,
+		`(.?)(?<!${escapedSymbol})(${escapedSymbol})([^${escapedSymbol}]+)(${escapedSymbol})(?!${escapedSymbol})(.)`,
 		'g'
 		'g'
 	);
 	);
 	return line.replace(regex, (match, l, left, content, right, r) => {
 	return line.replace(regex, (match, l, left, content, right, r) => {
 		const result =
 		const result =
-			(content.startsWith(leftSymbol) || content.endsWith(rightSymbol)) &&
-			(!l || (l && l.length > 0 && isChineseChar(l[l.length - 1]))) &&
-			(!r || (r && r.length > 0 && isChineseChar(r[0])));
+			(content.startsWith(leftSymbol) && l && l.length > 0 && isChineseChar(l[l.length - 1])) ||
+			(content.endsWith(rightSymbol) && r && r.length > 0 && isChineseChar(r[0]));
+
 		if (result) {
 		if (result) {
-			return ` ${left}${content}${right} `;
+			return `${l} ${left}${content}${right} ${r}`;
 		} else {
 		} else {
 			return match;
 			return match;
 		}
 		}