From 4ddf7348a4fb6d2e0eb6b89868321955af128d67 Mon Sep 17 00:00:00 2001 From: Zhicheng Wang Date: Wed, 7 Mar 2018 08:42:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E5=85=83=E7=B4=A0=E7=9A=84=E6=8B=86=E8=A7=A3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aio/tools/translator/utils.spec.ts | 28 ++++++++++++++++++++++++++++ aio/tools/translator/utils.ts | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/aio/tools/translator/utils.spec.ts b/aio/tools/translator/utils.spec.ts index 2a3f9c8bf4..7475b28a37 100644 --- a/aio/tools/translator/utils.spec.ts +++ b/aio/tools/translator/utils.spec.ts @@ -155,6 +155,34 @@ def`); +`); + }); + + it('拆解多行的成对 tag', function () { + const lines = normalizeLines(` +

+ a +

+ +

+ 一 +

+ +`); + expect(lines).eq(` + +

+ + a + +

+ +

+ + 一 + +

+ `); }); diff --git a/aio/tools/translator/utils.ts b/aio/tools/translator/utils.ts index 59d648bd70..b77b165342 100644 --- a/aio/tools/translator/utils.ts +++ b/aio/tools/translator/utils.ts @@ -63,7 +63,7 @@ export function normalizeLines(text: string): string { 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; + const multiLinePairedTagPattern = /\n( *)<(header|p)( *[^> \n]*)>\n*(.*?)\n*( *)<\/\2>( *)\n/g; text = text.replace(multiLinePairedTagPattern, '\n\n$1<$2$3>\n\n$4\n\n$5$6\n\n'); const multiLineCodePattern = /\n( *)```( *)\n/g;