@@ -201,10 +201,8 @@ export default async function readability(context, auditContext) {
201201 // Helper function to calculate readability score and create audit opportunity
202202 const analyzeReadability = async ( text , element , elementIndex ) => {
203203 try {
204- const normalized = normalizeReadabilityText ( text ) ;
205-
206204 // Check if text is in a supported language before analyzing readability
207- const detectedLanguage = getSupportedLanguage ( normalized ) ;
205+ const detectedLanguage = getSupportedLanguage ( text ) ;
208206 if ( ! detectedLanguage ) {
209207 return ; // Skip unsupported languages
210208 }
@@ -215,18 +213,18 @@ export default async function readability(context, auditContext) {
215213 // Use text-readability library for English, custom function for other languages
216214 let readabilityScore ;
217215 if ( detectedLanguage === 'english' ) {
218- readabilityScore = rs . fleschReadingEase ( normalized ) ;
216+ readabilityScore = rs . fleschReadingEase ( text ) ;
219217 } else {
220- readabilityScore = await calculateReadabilityScore ( normalized , detectedLanguage ) ;
218+ readabilityScore = await calculateReadabilityScore ( text , detectedLanguage ) ;
221219 }
222220
223221 if ( readabilityScore < TARGET_READABILITY_SCORE ) {
224222 poorReadabilityCount += 1 ;
225223
226224 // Truncate text for display
227- const displayText = normalized . length > MAX_CHARACTERS_DISPLAY
228- ? `${ normalized . substring ( 0 , MAX_CHARACTERS_DISPLAY ) } ...`
229- : normalized ;
225+ const displayText = text . length > MAX_CHARACTERS_DISPLAY
226+ ? `${ text . substring ( 0 , MAX_CHARACTERS_DISPLAY ) } ...`
227+ : text ;
230228
231229 const issueText = `Text element is difficult to read: "${ displayText } "` ;
232230
@@ -238,7 +236,7 @@ export default async function readability(context, auditContext) {
238236 fleschReadingEase : readabilityScore ,
239237 language : detectedLanguage ,
240238 seoRecommendation : 'Improve readability by using shorter sentences, simpler words, and clearer structure' ,
241- textContent : normalized , // Store normalized text for AI processing
239+ textContent : text , // Store normalized text for AI processing
242240 ...toElementTargets ( selector ) ,
243241 } ) ;
244242 }
@@ -302,7 +300,7 @@ export default async function readability(context, auditContext) {
302300 return tempDiv . text ( ) ;
303301 } )
304302 . map ( ( p ) => normalizeReadabilityText ( p ) )
305- . filter ( ( p ) => p . length >= MIN_TEXT_LENGTH ) ;
303+ . filter ( ( p ) => p . length >= MIN_TEXT_LENGTH && / \s / . test ( p ) ) ;
306304
307305 // Add promises for each paragraph
308306 paragraphs . forEach ( ( paragraph ) => {
0 commit comments