fix: 处理单 html tag 行的翻译问题
This commit is contained in:
parent
757526a6ed
commit
585e377fa8
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -74,7 +74,6 @@ export function gatherFromMarkdownFiles(directory: string): DictEntry[] {
|
|||
|
||||
export function purifyText(text): string {
|
||||
return text
|
||||
.replace(/^<(\w+)[\s\S]*?>([\s\S]*)<\/\1>$/, '$2')
|
||||
.replace(/^(.*)<code-example .*$/, '$1')
|
||||
.trim();
|
||||
}
|
||||
|
|
|
@ -11,4 +11,8 @@ describe('根据字典进行翻译', () => {
|
|||
it('查字典', () => {
|
||||
expect(lookup('# Forms')[0].translation).eql('# 表单');
|
||||
});
|
||||
|
||||
it('对包裹在 a 标签中的内容查字典', () => {
|
||||
expect(lookup('<a href=""># Forms</a>')[0].translation).eql('# 表单');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -8,7 +8,7 @@ import { indentOf, normalizeLines, repeat } from './utils';
|
|||
export const dict = require('./dict-3.json') as DictEntry[];
|
||||
|
||||
export function lookup(english: string, filename: RegExp = /.*/): DictEntry[] {
|
||||
let entries = dict
|
||||
const entries = dict
|
||||
.filter(entry => filename.test(entry.sourceFile))
|
||||
.filter(entry => kernelText(entry.original) === kernelText(english));
|
||||
return _.uniqBy(entries, 'translation');
|
||||
|
|
|
@ -35,7 +35,6 @@ def`);
|
|||
|
||||
Angular forms don't require a style library
|
||||
|
||||
|
||||
</header>
|
||||
|
||||
`);
|
||||
|
|
|
@ -53,9 +53,15 @@ 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 htmlTagPattern = /(\s*<.*?>\s*?)\n/g;
|
||||
text = text.replace(htmlTagPattern, '\n\n$1\n\n');
|
||||
text = text.replace(/\n\n+/, '\n\n');
|
||||
const htmlTagPattern = /(\s*)<(\/?\w+)(.*?)>(\s*?)\n/g;
|
||||
text = text.replace(htmlTagPattern, (line, _1, _2, _3, _4) => {
|
||||
if (_2 === 'a') {
|
||||
return line;
|
||||
} else {
|
||||
return `\n\n${line}\n\n`;
|
||||
}
|
||||
});
|
||||
text = text.replace(/\n\s*\n+/g, '\n\n');
|
||||
return text;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue