webpack-gc-i18n-plugin 1.1.8 → 1.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/customLoader/index.cjs +82 -4
- package/dist/customLoader/index.cjs.map +1 -1
- package/dist/customLoader/index.mjs +82 -4
- package/dist/customLoader/index.mjs.map +1 -1
- package/dist/index.cjs +82 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -6
- package/dist/index.mjs +83 -47
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -425,7 +425,7 @@ const REGEX_MAP = {
|
|
|
425
425
|
*/
|
|
426
426
|
function splitByRegex(str, separatorRegex) {
|
|
427
427
|
// 定义标点符号的正则表达式
|
|
428
|
-
const punctuationRegex = /[
|
|
428
|
+
const punctuationRegex = /[,。?!《》()(),..:!?""'';'"、0-9\n\r\t\v\f]/;
|
|
429
429
|
// 创建一个新的正则表达式,用于分割字符串
|
|
430
430
|
const splitRegex = new RegExp(`(${separatorRegex.source}|${punctuationRegex.source})`, separatorRegex.flags);
|
|
431
431
|
|
|
@@ -435,7 +435,7 @@ function splitByRegex(str, separatorRegex) {
|
|
|
435
435
|
let currentMatch = '';
|
|
436
436
|
|
|
437
437
|
// 定义连接标点符号的正则表达式
|
|
438
|
-
const connectPunctuationRegex = /[
|
|
438
|
+
const connectPunctuationRegex = /[,。?!《》()(),..:!?;'"、0-9]/;
|
|
439
439
|
// 创建一个新的正则表达式,用于检测是否需要连接
|
|
440
440
|
const connectRegex = new RegExp(`(${separatorRegex.source}|${connectPunctuationRegex.source})`, separatorRegex.flags);
|
|
441
441
|
|
|
@@ -482,7 +482,85 @@ function splitByRegex(str, separatorRegex) {
|
|
|
482
482
|
if (tempStr) {
|
|
483
483
|
finalResult.push(tempStr);
|
|
484
484
|
}
|
|
485
|
-
return finalResult;
|
|
485
|
+
return mergeInlineTextSeparatedOriginChunks(finalResult, separatorRegex);
|
|
486
|
+
}
|
|
487
|
+
function mergeInlineTextSeparatedOriginChunks(strArray, separatorRegex) {
|
|
488
|
+
const result = [];
|
|
489
|
+
for (let i = 0; i < strArray.length; i++) {
|
|
490
|
+
let current = strArray[i];
|
|
491
|
+
if (!separatorRegex.test(current) && i + 1 < strArray.length && separatorRegex.test(strArray[i + 1])) {
|
|
492
|
+
const {
|
|
493
|
+
beforeInlineText,
|
|
494
|
+
inlineText
|
|
495
|
+
} = splitTrailingInlineText(current);
|
|
496
|
+
if (inlineText && /[^\s\u00a0]/.test(inlineText)) {
|
|
497
|
+
if (beforeInlineText) {
|
|
498
|
+
result.push(beforeInlineText);
|
|
499
|
+
}
|
|
500
|
+
current = `${normalizeInlineTextPrefix(inlineText)}${strArray[i + 1]}`;
|
|
501
|
+
i += 1;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
if (!separatorRegex.test(current) && isInlineTextSeparator(current) && /[^\s\u00a0]/.test(current) && i + 1 < strArray.length && separatorRegex.test(strArray[i + 1])) {
|
|
505
|
+
current = `${normalizeInlineTextPrefix(current)}${strArray[i + 1]}`;
|
|
506
|
+
i += 1;
|
|
507
|
+
}
|
|
508
|
+
if (separatorRegex.test(current)) {
|
|
509
|
+
while (i + 2 < strArray.length && isInlineTextSeparator(strArray[i + 1]) && separatorRegex.test(strArray[i + 2])) {
|
|
510
|
+
current += `${normalizeInlineTextSeparator(strArray[i + 1])}${strArray[i + 2]}`;
|
|
511
|
+
i += 2;
|
|
512
|
+
}
|
|
513
|
+
if (i + 1 < strArray.length) {
|
|
514
|
+
const {
|
|
515
|
+
inlineText,
|
|
516
|
+
rest
|
|
517
|
+
} = splitLeadingInlineText(strArray[i + 1]);
|
|
518
|
+
if (inlineText) {
|
|
519
|
+
current += normalizeInlineTextSeparator(inlineText);
|
|
520
|
+
strArray[i + 1] = rest;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
if (current) {
|
|
525
|
+
result.push(current);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
return result;
|
|
529
|
+
}
|
|
530
|
+
function isInlineTextSeparator(value) {
|
|
531
|
+
return value !== '' && !/[<>]/.test(value);
|
|
532
|
+
}
|
|
533
|
+
function normalizeInlineTextSeparator(value) {
|
|
534
|
+
return /^[\s\u00a0]+$/.test(value) ? ' ' : value.replace(/[\s\u00a0]+/g, ' ');
|
|
535
|
+
}
|
|
536
|
+
function normalizeInlineTextPrefix(value) {
|
|
537
|
+
return value.replace(/[\s\u00a0]+/g, ' ').trimStart();
|
|
538
|
+
}
|
|
539
|
+
function splitLeadingInlineText(value) {
|
|
540
|
+
const tagIndex = value.search(/[<>]/);
|
|
541
|
+
if (tagIndex === -1) {
|
|
542
|
+
return {
|
|
543
|
+
inlineText: value,
|
|
544
|
+
rest: ''
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
return {
|
|
548
|
+
inlineText: value.slice(0, tagIndex),
|
|
549
|
+
rest: value.slice(tagIndex)
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
function splitTrailingInlineText(value) {
|
|
553
|
+
const tagEndIndex = value.lastIndexOf('>');
|
|
554
|
+
if (tagEndIndex === -1) {
|
|
555
|
+
return {
|
|
556
|
+
beforeInlineText: '',
|
|
557
|
+
inlineText: value
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
return {
|
|
561
|
+
beforeInlineText: value.slice(0, tagEndIndex + 1),
|
|
562
|
+
inlineText: value.slice(tagEndIndex + 1)
|
|
563
|
+
};
|
|
486
564
|
}
|
|
487
565
|
|
|
488
566
|
/**
|
|
@@ -492,7 +570,7 @@ function splitByRegex(str, separatorRegex) {
|
|
|
492
570
|
*/
|
|
493
571
|
function checkNeedSplit(str) {
|
|
494
572
|
// 检查字符串中是否包含需要切割的特殊字符
|
|
495
|
-
return str.includes('
|
|
573
|
+
return str.includes('\\') || str.includes('>') || str.includes('<');
|
|
496
574
|
}
|
|
497
575
|
|
|
498
576
|
/**
|