parent
1c028aee24
commit
076cd7940b
|
@ -100,7 +100,7 @@ def
|
|||
|
||||
<th>
|
||||
|
||||
line
|
||||
line
|
||||
|
||||
</th>
|
||||
|
||||
|
@ -138,6 +138,19 @@ def
|
|||
`);
|
||||
});
|
||||
|
||||
it('拆解 code-example', function () {
|
||||
const lines = normalizeLines(`
|
||||
<code-example language="sh" class="code-shell">
|
||||
ng generate directive highlight
|
||||
|
||||
`);
|
||||
expect(lines).eql(`
|
||||
<code-example language="sh" class="code-shell">
|
||||
|
||||
ng generate directive highlight
|
||||
`);
|
||||
});
|
||||
|
||||
it('拆解 @a 标记', function () {
|
||||
const lines = normalizeLines(`
|
||||
a
|
||||
|
@ -177,13 +190,13 @@ def
|
|||
it('拆解多行的成对 tag', function () {
|
||||
const lines = normalizeLines(`
|
||||
<header>
|
||||
Angular forms don't require a style library
|
||||
Angular forms don't require a style library
|
||||
</header>
|
||||
`);
|
||||
expect(lines).eq(`
|
||||
<header>
|
||||
|
||||
Angular forms don't require a style library
|
||||
Angular forms don't require a style library
|
||||
|
||||
</header>
|
||||
`);
|
||||
|
@ -192,7 +205,7 @@ def
|
|||
it('拆解多行的成对 tag', function () {
|
||||
const lines = normalizeLines(`
|
||||
<p>
|
||||
a
|
||||
a
|
||||
</p>
|
||||
|
||||
<p>
|
||||
|
@ -203,7 +216,7 @@ def
|
|||
expect(lines).eq(`
|
||||
<p>
|
||||
|
||||
a
|
||||
a
|
||||
|
||||
</p>
|
||||
|
||||
|
@ -241,19 +254,19 @@ def
|
|||
|
||||
<li>
|
||||
|
||||
<a href="#">a</a>
|
||||
<a href="#">a</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
<a href="#">b</a>
|
||||
<a href="#">b</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
<a href="#">c</a>
|
||||
<a href="#">c</a>
|
||||
|
||||
</li>
|
||||
|
||||
|
|
|
@ -50,34 +50,35 @@ export function normalizeLines(text: string): string {
|
|||
// 列表、标题等自带换行含义的markdown
|
||||
const blockElementPattern = /(?=\n *(\d+\.|-|\*) )\n/g;
|
||||
text = text.replace(blockElementPattern, '\n\n');
|
||||
const hxPattern = /(\n *#.*)\n/g;
|
||||
text = text.replace(hxPattern, '\n$1\n\n');
|
||||
const leadHxPattern = /^( *#.*)\n/g;
|
||||
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|li)( ?[^> \n]*)>(.*)<\/\2>( *)/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');
|
||||
const oneLineBrTagPattern = /\n( *)(<br class="clear">)( *)\n/g;
|
||||
text = text.replace(oneLineBrTagPattern, '\n\n$1$2$3\n\n');
|
||||
const atTagCommentPattern = /\n( *)({@a.*})( *)\n/g;
|
||||
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|p)( *[^> \n]*)>\n*(.*?)\n*( *)<\/\2>( *)\n/g;
|
||||
text = text.replace(multiLinePairedTagPattern, '\n\n$1<$2$3>\n\n$1 $4\n\n$1</$2>$6\n\n');
|
||||
const hxPattern = /(\n *# .*)(?=\n)/g;
|
||||
text = text.replace(hxPattern, '\n$1\n');
|
||||
const oneLinePairedTagPattern = /\n( *)<(p|div|h\d+|a|code-example)( ?[^>\n]*)>([^<\n]*)<\/\2>( *)(?=\n)/g;
|
||||
text = text.replace(oneLinePairedTagPattern, '\n\n$1<$2$3>$4</$2>$5\n');
|
||||
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');
|
||||
const oneLineCommentPattern = /\n( *)(<!--.*-->)( *)(?=\n)/g;
|
||||
text = text.replace(oneLineCommentPattern, '\n\n$1$2$3\n');
|
||||
const oneLineBrTagPattern = /\n( *)(<br class="clear">)( *)(?=\n)/g;
|
||||
text = text.replace(oneLineBrTagPattern, '\n\n$1$2$3\n');
|
||||
const atTagCommentPattern = /\n( *)({@a.*})( *)(?=\n)/g;
|
||||
text = text.replace(atTagCommentPattern, '\n\n$1$2$3\n');
|
||||
const oneLineClosedTagPattern = /\n( *)<(hr|p)(\/?)>( *)(?=\n)/g;
|
||||
text = text.replace(oneLineClosedTagPattern, '\n\n$1<$2$3>$4\n');
|
||||
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');
|
||||
|
||||
const blockTagPattern = /\n( *)<(\/?)(td|th|div)( *[^> \n]*)>( *)\n/g;
|
||||
text = text.replace(blockTagPattern, '\n\n$1<$2$3$4>$5\n\n');
|
||||
const blockTagPattern = /\n( *)<(\/?)(td|th|div|code-example)( *[^>\n]*)>( *)(?=\n)/g;
|
||||
text = text.replace(blockTagPattern, '\n\n$1<$2$3$4>$5\n');
|
||||
|
||||
const multiLineCodePattern = /\n( *)```(\w*)( *)\n/g;
|
||||
text = text.replace(multiLineCodePattern, '\n\n$1```$2$3\n\n');
|
||||
const multiLineCodePattern = /\n( *)```(\w*)( *)(?=\n)/g;
|
||||
text = text.replace(multiLineCodePattern, '\n\n$1```$2$3\n');
|
||||
|
||||
const multipleBlankLinePattern = /\n\s*\n+/g;
|
||||
text = text.replace(multipleBlankLinePattern, '\n\n');
|
||||
return text.replace(/^\n+/, '\n').replace(/\n+$/, '\n');
|
||||
|
||||
text = text.replace(/^\n+/, '\n').replace(/\n+$/, '\n');
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
export function indentOf(line): number {
|
||||
|
|
Loading…
Reference in New Issue