mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-08-07 17:32:58 +02:00
feat: enhance readability analysis by improving markdown stripping and updating score color logic
This commit is contained in:
@@ -15,11 +15,13 @@ export class ReadabilityHelper {
|
||||
*/
|
||||
private static stripMarkdown(text: string): string {
|
||||
return text
|
||||
.replace(/\{\{<[\s\S]*?>}}/g, '') // Hugo shortcodes (removes base64 blobs, captions, etc.)
|
||||
.replace(/```[\s\S]*?```/g, '') // fenced code blocks (must run before inline code)
|
||||
.replace(/`[^`\n]+`/g, '') // inline code
|
||||
.replace(/!\[.*?\]\(.*?\)/g, '') // images
|
||||
.replace(/\[([^\]]+)\]\(.*?\)/g, '$1') // links → text only
|
||||
.replace(/^\|.*\|$/gm, '') // table rows
|
||||
.replace(/#{1,6}\s/g, '') // headings
|
||||
.replace(/`{1,3}[^`]*`{1,3}/g, '') // inline + fenced code
|
||||
.replace(/```[\s\S]*?```/g, '') // fenced blocks
|
||||
.replace(/[*_]{1,3}([^*_]+)[*_]{1,3}/g, '$1') // bold/italic
|
||||
.replace(/>\s/g, '') // blockquotes
|
||||
.replace(/[-*+]\s/g, '') // list bullets
|
||||
|
||||
@@ -17,7 +17,8 @@ interface Props {
|
||||
minScore: number;
|
||||
}
|
||||
|
||||
const scoreColor = (score: number): string => {
|
||||
const scoreColor = (score: number, isLow: boolean): string => {
|
||||
if (isLow) { return 'text-[var(--vscode-problemsWarningIcon-foreground)]'; }
|
||||
if (score >= 60) { return 'text-[var(--vscode-testing-iconPassed)]'; }
|
||||
if (score >= 30) { return 'text-[var(--vscode-problemsWarningIcon-foreground)]'; }
|
||||
return 'text-[var(--vscode-problemsErrorIcon-foreground)]';
|
||||
@@ -63,7 +64,7 @@ const ReadabilityScore: React.FunctionComponent<Props> = ({ readability, minScor
|
||||
<VSCodeTableRow>
|
||||
<VSCodeTableCell>{localize(LocalizationKey.panelContentHealthReadabilityLabel)}</VSCodeTableCell>
|
||||
<VSCodeTableCell>
|
||||
<span className={`font-semibold ${scoreColor(readability.score)}`}>
|
||||
<span className={`font-semibold ${scoreColor(readability.score, isLow)}`}>
|
||||
{readability.score}
|
||||
</span>
|
||||
<span className='text-[var(--vscode-descriptionForeground)] ml-1'>
|
||||
|
||||
Reference in New Issue
Block a user