fix(v2): ignore export declarations in excerpt (#3703)

This commit is contained in:
Alexey Pyltsyn 2020-11-06 19:49:59 +03:00 committed by GitHub
parent 86be6cec1e
commit f2d1330207
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 13 deletions

View file

@ -188,21 +188,21 @@ export function getSubFolder(file: string, refDir: string): string | null {
return match && match[1];
}
// Regex for an import statement.
const importRegexString = '^(.*import){1}(.+){0,1}\\s[\'"](.+)[\'"];?';
export function createExcerpt(fileString: string): string | undefined {
let fileContent = fileString.trimLeft();
if (RegExp(importRegexString).test(fileContent)) {
fileContent = fileContent
.replace(RegExp(importRegexString, 'gm'), '')
.trimLeft();
}
const fileLines = fileContent.split('\n');
const fileLines = fileString.trimLeft().split('\n');
/* eslint-disable no-continue */
for (const fileLine of fileLines) {
// Skip empty line.
if (!fileLine.trim()) {
continue;
}
// Skip import/export declaration.
if (/^.*import\s.*from.*;?|export\s.*{.*};?/.test(fileLine)) {
continue;
}
const cleanedLine = fileLine
// Remove HTML tags.
.replace(/<[^>]*>/g, '')