File tree Expand file tree Collapse file tree
src/components/map-projects Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import MapButton from './MapButton'
1313import ConceptSummaryProperties from '../concepts/ConceptSummaryProperties'
1414
1515
16- const getBestSynonym = synonyms => {
16+ const getBestSynonym = ( synonyms = [ ] ) => {
1717 return synonyms
1818 . map ( text => {
1919 const matches = [ ...text . matchAll ( / < e m > ( .* ?) < \/ e m > / g) ] ;
@@ -23,23 +23,17 @@ const getBestSynonym = synonyms => {
2323 ) ;
2424
2525 const emTag = `<em>${ longestMatch } </em>` ;
26- const startsWithMatch = text . indexOf ( emTag ) === 0 ;
27-
28- // prefer exact "<em>...</em>"
29- const isExactEmOnly = text . trim ( ) === emTag ;
30-
3126 return {
3227 text,
33- longestMatch,
3428 length : longestMatch . length ,
35- startsWithMatch ,
36- isExactEmOnly
29+ isExact : text . trim ( ) === emTag ,
30+ startsWith : text . startsWith ( emTag )
3731 } ;
3832 } )
3933 . sort ( ( a , b ) => {
40- if ( b . length !== a . length ) return b . length - a . length ; // longest match first
41- if ( b . isExactEmOnly !== a . isExactEmOnly ) return b . isExactEmOnly ? 1 : - 1 ; // ✅ exact "<em>...</em>" wins
42- if ( b . startsWithMatch !== a . startsWithMatch ) return b . startsWithMatch ? 1 : - 1 ; // prefer start
34+ if ( b . isExact !== a . isExact ) return b . isExact ? 1 : - 1 ; // ✅ exact ALWAYS first
35+ if ( b . length !== a . length ) return b . length - a . length ; // longer match
36+ if ( b . startsWith !== a . startsWith ) return b . startsWith ? 1 : - 1 ;
4337 return 0 ;
4438 } ) [ 0 ] ?. text ;
4539} ;
You can’t perform that action at this time.
0 commit comments