diff --git a/aio/tools/translator/utils.spec.ts b/aio/tools/translator/utils.spec.ts
index 6e9caf785b..2a3f9c8bf4 100644
--- a/aio/tools/translator/utils.spec.ts
+++ b/aio/tools/translator/utils.spec.ts
@@ -52,6 +52,95 @@ def`);
b
`);
});
+ it('拆解单行的 h\\d 标签', function () {
+ const lines = normalizeLines(`
+ a
+
line
+ b
+`);
+ expect(lines).eql(`
+ a
+
+
+
+ line
+
+
+
+ b
+`);
+ });
+
+ it('拆解单行的 th 标签', function () {
+ const lines = normalizeLines(`
+ a
+ line |
+ b
+`);
+ expect(lines).eql(`
+ a
+
+
+
+ line
+
+ |
+
+ b
+`);
+ });
+
+ it('拆解单行注释', function () {
+ const lines = normalizeLines(`
+ a
+
+ b
+`);
+ expect(lines).eql(`
+ a
+
+
+
+ b
+`);
+ });
+
+ it('拆解 @a 标记', function () {
+ const lines = normalizeLines(`
+ a
+ {@a test}
+ b
+`);
+ expect(lines).eql(`
+ a
+
+ {@a test}
+
+ b
+`);
+ });
+
+ it('拆解多行代码', function () {
+ const lines = normalizeLines(`
+ a
+ \`\`\`
+ var a = 1
+ \`\`\`
+ b
+`);
+ expect(lines).eql(`
+ a
+
+ \`\`\`
+
+ var a = 1
+
+ \`\`\`
+
+ b
+`);
+ });
+
it('拆解多行的成对 tag', function () {
const lines = normalizeLines(`
@@ -76,4 +165,5 @@ def`);
const lines = normalizeLines(`\n a \n\n\n b `);
expect(lines).eql(`\n a \n\n b `);
});
+
});
diff --git a/aio/tools/translator/utils.ts b/aio/tools/translator/utils.ts
index 4f7455549e..59d648bd70 100644
--- a/aio/tools/translator/utils.ts
+++ b/aio/tools/translator/utils.ts
@@ -55,10 +55,20 @@ export function normalizeLines(text: string): string {
text = text.replace(leadHxPattern, '$1\n\n');
const oneLinePairedTagPattern = /\n( *)<(p|code-example|div)( ?[^> \n]*)>([^<\n]*)<\/\2>( *)\n/g;
text = text.replace(oneLinePairedTagPattern, '\n\n$1<$2$3>$4$2>$5\n\n');
+ const oneLineHnTagPattern = /\n( *)<(h\d+|th|td)( ?[^> \n]*)>([^<\n]*)<\/\2>( *)\n/g;
+ text = text.replace(oneLineHnTagPattern, '\n\n$1<$2$3>\n\n$1$4\n\n$1$2>$5\n\n');
+ const oneLineCommentPattern = /\n( *)()( *)\n/g;
+ text = text.replace(oneLineCommentPattern, '\n\n$1$2$3\n\n');
+ const atTagCommentPattern = /\n( *)({@a.*})( *)\n/g;
+ text = text.replace(atTagCommentPattern, '\n\n$1$2$3\n\n');
const oneLineClosedTagPattern = /\n( *)<(hr|p)(\/?)>( *)\n/g;
text = text.replace(oneLineClosedTagPattern, '\n\n$1<$2$3>$4\n\n');
const multiLinePairedTagPattern = /\n( *)<(header)( *[^> \n]*)>\n?(.*?)\n?( *)<\/\2>( *)\n/g;
text = text.replace(multiLinePairedTagPattern, '\n\n$1<$2$3>\n\n$4\n\n$5$2>$6\n\n');
+
+ const multiLineCodePattern = /\n( *)```( *)\n/g;
+ text = text.replace(multiLineCodePattern, '\n\n$1```$2\n\n');
+
const multipleBlankLinePattern = /\n\s*\n+/g;
text = text.replace(multipleBlankLinePattern, '\n\n');
return text;