File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed
Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 22
33Keep track of any changes you make here, so they can just be copied into the
44changelog after releasing them.
5+
6+ ### Fixed
7+
8+ - Detect that string is JSX if it contains a ` className ` -attribute
Original file line number Diff line number Diff line change @@ -356,3 +356,42 @@ test("should match long HTML snippet", () => {
356356
357357 expect ( isHTML ( text ) ) . toBe ( true ) ;
358358} ) ;
359+
360+ test ( "should not match JSX that contains className attribute" , ( ) => {
361+ const text = html `
362+ < div className ="bg-gray-50 ">
363+ < div
364+ className ="max-w-7xl mx-auto py-12 px-4 sm:px-6 lg:py-16 lg:px-8 lg:flex lg:items-center lg:justify-between "
365+ >
366+ < h2
367+ className ="text-3xl font-extrabold tracking-tight text-gray-900 sm:text-4xl "
368+ >
369+ < span className ="block "> Ready to dive in?</ span >
370+ < span className ="block text-indigo-600 "
371+ > Start your free trial today.</ span
372+ >
373+ </ h2 >
374+ < div className ="mt-8 lex lg:mt-0 lg:flex-shrink-0 ">
375+ < div className ="inline-flex rounded-md shadow ">
376+ < a
377+ href ="# "
378+ className ="inline-flex items-center justify-center px-5 py-3 border border-transparent text-base font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 "
379+ >
380+ Get started
381+ </ a >
382+ </ div >
383+ < div className ="ml-3 inline-flex rounded-md shadow ">
384+ < a
385+ href ="# "
386+ className ="inline-flex items-center justify-center px-5 py-3 border border-transparent text-base font-medium rounded-md text-indigo-600 bg-white hover:bg-indigo-50 "
387+ >
388+ Learn more
389+ </ a >
390+ </ div >
391+ </ div >
392+ </ div >
393+ </ div >
394+ ` ;
395+
396+ expect ( isHTML ( text ) ) . toBe ( false ) ;
397+ } ) ;
Original file line number Diff line number Diff line change 11const UPPERCASE_TAGS = / < \s * [ A - Z ] / ;
2+ const CLASSNAME_ATTRIBUTE = / < .* c l a s s N a m e .* > / ;
23
34/**
45 * Checks if a given input string is HTML code.
@@ -15,5 +16,9 @@ export function isHTML(text: string): boolean {
1516 return false ;
1617 }
1718
19+ if ( CLASSNAME_ATTRIBUTE . test ( trimmedText ) ) {
20+ return false ;
21+ }
22+
1823 return true ;
1924}
You can’t perform that action at this time.
0 commit comments