From 4c6b614064baa75bd33341b7b986c359be07efd2 Mon Sep 17 00:00:00 2001 From: Zhicheng Wang Date: Wed, 7 Mar 2018 09:33:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8B=86=E8=A7=A3=E5=8D=95=E8=A1=8C=20l?= =?UTF-8?q?i?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aio/tools/translator/utils.spec.ts | 13 +++++++++++++ aio/tools/translator/utils.ts | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/aio/tools/translator/utils.spec.ts b/aio/tools/translator/utils.spec.ts index b17dde763c..927f1b207a 100644 --- a/aio/tools/translator/utils.spec.ts +++ b/aio/tools/translator/utils.spec.ts @@ -210,6 +210,19 @@ def`); +`); + }); + it('拆解独行的 li', function () { + expect(normalizeLines(` +
  • abc
  • +`)).eql(` + +
  • + +abc + +
  • + `); }); it('不要拆解行内的 html tag', function () { diff --git a/aio/tools/translator/utils.ts b/aio/tools/translator/utils.ts index b0cba68a95..a7e6046403 100644 --- a/aio/tools/translator/utils.ts +++ b/aio/tools/translator/utils.ts @@ -55,7 +55,7 @@ export function normalizeLines(text: string): string { text = text.replace(leadHxPattern, '$1\n\n'); const oneLinePairedTagPattern = /\n( *)<(p|code-example|div|h\d+|a)( ?[^> \n]*)>([^<\n]*)<\/\2>( *)\n/g; text = text.replace(oneLinePairedTagPattern, '\n\n$1<$2$3>$4$5\n\n'); - const oneLineThTdTagPattern = /\n( *)<(th|td)( ?[^> \n]*)>([^<\n]*)<\/\2>( *)\n/g; + const oneLineThTdTagPattern = /\n( *)<(th|td|li)( ?[^> \n]*)>(.*)<\/\2>( *)\n/g; text = text.replace(oneLineThTdTagPattern, '\n\n$1<$2$3>\n\n$1$4\n\n$1$5\n\n'); const oneLineCommentPattern = /\n( *)()( *)\n/g; text = text.replace(oneLineCommentPattern, '\n\n$1$2$3\n\n');