|
|
@@ -114,6 +114,33 @@ class BlankPlaceholderRenderer
|
|
|
return self::DEFAULT_BLANK_SPAN;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 统一句尾标点(仅处理句尾,不影响中间小数/表达式)
|
|
|
+ *
|
|
|
+ * $mode:
|
|
|
+ * - remove: 去掉句尾句号
|
|
|
+ * - dot: 句尾统一为英文实心点 "."
|
|
|
+ * - cn: 句尾统一为中文句号 "。"
|
|
|
+ */
|
|
|
+ public static function normalizeTerminalPunctuation(string $content, string $mode): string
|
|
|
+ {
|
|
|
+ $replacement = match ($mode) {
|
|
|
+ 'remove' => '',
|
|
|
+ 'dot' => '.',
|
|
|
+ 'cn' => '。',
|
|
|
+ default => null,
|
|
|
+ };
|
|
|
+ if ($replacement === null) {
|
|
|
+ return $content;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 先处理数学片段尾点(如 "$.$" / "$。$" / "$.$")。
|
|
|
+ $content = preg_replace('/\$\s*[\..。]\s*\$(?=\s*(?:(?:<\/[^>]+>|<[^>]+\/>)\s*)*$)/u', $replacement, $content);
|
|
|
+
|
|
|
+ // 再处理普通句尾点。
|
|
|
+ return preg_replace('/[\..。](?=\s*(?:(?:<\/[^>]+>|<[^>]+\/>)\s*)*$)/u', $replacement, $content);
|
|
|
+ }
|
|
|
+
|
|
|
private static function normalizeChineseTerminalPeriod(string $content): string
|
|
|
{
|
|
|
// 仅在存在中文语境时,把句末英文句号统一为中文句号。
|
|
|
@@ -121,9 +148,6 @@ class BlankPlaceholderRenderer
|
|
|
return $content;
|
|
|
}
|
|
|
|
|
|
- // 先处理数学片段尾点(如 "$.$" / "$.$")。
|
|
|
- $content = preg_replace('/\$\s*[\..]\s*\$(?=\s*(?:<\/[^>]+>\s*)*$)/u', '。', $content);
|
|
|
-
|
|
|
- return preg_replace('/[\..](?=\s*(?:<\/[^>]+>\s*)*$)/u', '。', $content);
|
|
|
+ return self::normalizeTerminalPunctuation($content, 'cn');
|
|
|
}
|
|
|
}
|