feat: enhance readability analysis by improving markdown stripping and updating score color logic

This commit is contained in:
Elio Struyf
2026-06-12 08:40:24 +02:00
parent 6b0c6518e9
commit 90e814c11d
2 changed files with 7 additions and 4 deletions
+4 -2
View File
@@ -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'>