fix: 拆解单行自封闭 tag

This commit is contained in:
Zhicheng Wang 2018-03-06 17:18:33 +08:00
parent 73e4efa80d
commit fee2468d41
2 changed files with 19 additions and 2 deletions

View File

@ -37,6 +37,21 @@ def`);
b
`);
});
it('拆解单行的自封闭 tag', function () {
const lines = normalizeLines(`
a
<hr/>
b
`);
expect(lines).eql(`
a
<hr/>
b
`);
});
it('拆解多行的成对 tag', function () {
const lines = normalizeLines(`
<header>

View File

@ -53,8 +53,10 @@ export function normalizeLines(text: string): string {
text = text.replace(hxPattern, '\n$1\n\n');
const leadHxPattern = /^( *#.*)\n/g;
text = text.replace(leadHxPattern, '$1\n\n');
const oneLinePairedTagPattern = /(\n *<div +[^> \n]*>[^<\n]*<\/div> *\n)/g;
text = text.replace(oneLinePairedTagPattern, '\n\n$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 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 multipleBlankLinePattern = /\n\s*\n+/g;