mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-18 17:17:57 +02:00
fix: ignore code block lines when create excerpt (#5495)
This commit is contained in:
parent
ebf81b6ef6
commit
578470a24c
2 changed files with 22 additions and 0 deletions
|
@ -18,6 +18,7 @@ export function createExcerpt(fileString: string): string | undefined {
|
|||
// Remove Markdown alternate title
|
||||
.replace(/^[^\n]*\n[=]+/g, '')
|
||||
.split('\n');
|
||||
let inCode = false;
|
||||
|
||||
/* eslint-disable no-continue */
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
|
@ -32,6 +33,14 @@ export function createExcerpt(fileString: string): string | undefined {
|
|||
continue;
|
||||
}
|
||||
|
||||
// Skip code block line.
|
||||
if (fileLine.trim().startsWith('```')) {
|
||||
inCode = !inCode;
|
||||
continue;
|
||||
} else if (inCode) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const cleanedLine = fileLine
|
||||
// Remove HTML tags.
|
||||
.replace(/<[^>]*>/g, '')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue