import { DictEntry } from './dict-entry'; import { isTranslation } from './extractor'; export function translationHasNotCodeExample(entry: DictEntry): boolean { return entry.translation.indexOf(')( *)(?=\n)/g; text = text.replace(oneLineBrTagPattern, '\n\n$1$2$3\n'); // 原文中有 back to top 被分成两行的情况,这里把它标准化一下 const specialBackToTopPattern = /Back to top\s+<\/a>/g; text = text.replace(specialBackToTopPattern, 'Back to top'); const backToTopPattern = /\n( *)(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; text = text.replace(oneLineClosedTagPattern, '\n\n$1<$2$3>$4\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$6\n'); const trTagPattern = /( *)(\n]*>)(.*)(<\/tr>)/g; text = text.replace(trTagPattern, '\n\n$1$2\n\n$1 $3\n\n$1$4\n\n'); const thTdTagPattern = /( *)<(th|td)\b( *[^>\n]*)>(.*?)<\/\2>/g; text = text.replace(thTdTagPattern, '\n\n$1<$2$3>\n\n$1 $4\n\n$1\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'); 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'); text = text.replace(/^\n+/, '\n').replace(/\n+$/, '\n'); return text; } export function indentOf(line): number { let pattern = /^( *)[\s\S]*/; if (!pattern.test(line)) { return 0; } const leadSpaces = line.replace(pattern, '$1').length; if (/^ *(\d+\.|-|\*) /.test(line)) { return leadSpaces + 3; } else { return leadSpaces; } } export function repeat(indent: number): string { let result = ''; for (let i = 0; i < indent; ++i) { result = result + ' '; } return result; }