fix: 解决其他元素的拆解问题

This commit is contained in:
Zhicheng Wang 2018-03-07 08:42:26 +08:00
parent f89d728818
commit 4ddf7348a4
2 changed files with 29 additions and 1 deletions

View File

@ -155,6 +155,34 @@ def`);
</header>
`);
});
it('拆解多行的成对 tag', function () {
const lines = normalizeLines(`
<p>
a
</p>
<p>
</p>
`);
expect(lines).eq(`
<p>
a
</p>
<p>
</p>
`);
});

View File

@ -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</$2>$6\n\n');
const multiLineCodePattern = /\n( *)```( *)\n/g;