fix: 拆解单行 li

This commit is contained in:
Zhicheng Wang 2018-03-07 09:33:42 +08:00
parent 4c10eb42b5
commit 4c6b614064
2 changed files with 14 additions and 1 deletions

View File

@ -210,6 +210,19 @@ def`);
</td>
`);
});
it('拆解独行的 li', function () {
expect(normalizeLines(`
<li><span>abc</span></li>
`)).eql(`
<li>
<span>abc</span>
</li>
`);
});
it('不要拆解行内的 html tag', function () {

View File

@ -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</$2>$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</$2>$5\n\n');
const oneLineCommentPattern = /\n( *)(<!--.*-->)( *)\n/g;
text = text.replace(oneLineCommentPattern, '\n\n$1$2$3\n\n');