fix: 人工修订自动翻译

fix: 拆解 tr
fix: 特殊拆解 back to top
This commit is contained in:
Zhicheng Wang 2018-03-07 12:45:12 +08:00
parent 9adeb14f3a
commit a94e7cba14
5 changed files with 20 additions and 2 deletions

View File

@ -4662,4 +4662,5 @@ Useful tools and tips for Angular.
<a href="#toc">Back to top</a>
<a href="#toc">回到顶部</a>

View File

@ -1520,7 +1520,7 @@ Here's how the table renders:
</td><td>
Six
六列
</td></tr>

View File

@ -3,5 +3,5 @@
import { dirs } from '../dirs';
import { translateFile } from '../translate';
const filename = 'guide/router.md';
const filename = 'guide/template-syntax.md';
translateFile(__dirname + '/../../../../../content-en/' + filename, dirs.content + filename);

View File

@ -279,6 +279,18 @@ ng generate directive highlight
</td>
`);
});
it('拆解任意位置的 <tr>', function () {
expect(normalizeLines(`
<tr><td>abc</td></tr>
`)).eql(`
<tr>
<td>abc</td>
</tr>
`);
});
it('拆解独行的 li', function () {
expect(normalizeLines(`
<ul>

View File

@ -60,6 +60,8 @@ export function normalizeLines(text: string): string {
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 backToTopPattern = /\n( *)(<a href="#toc">Back to top<\/a>)( *)(?=\n)/g;
text = text.replace(backToTopPattern, '\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)(\/?)>( *)(?=\n)/g;
@ -67,6 +69,9 @@ export function normalizeLines(text: string): string {
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');
const trTagPattern = /( *)(<tr\b *[^>\n]*>)(.*)(<\/tr>)/g;
text = text.replace(trTagPattern, '\n\n$1$2\n\n$1 $3\n\n$1$4\n\n');
const blockTagPattern = /\n( *)<(\/?)(td|th|div|code-example|code-tabs|h\d+|p|tr)\b( *[^>\n]*)>( *)(?=\n)/g;
text = text.replace(blockTagPattern, '\n\n$1<$2$3$4>$5\n');