@@ -16,14 +16,16 @@ export function checkHyphenation (text) {
1616 const occurences = [ ]
1717 const hyphenTerms = [ ]
1818 const hyphenTermsOccurences = [ ]
19+ const termCount = { }
1920 for ( const [ lineIdx , line ] of textLines . entries ( ) ) {
2021 for ( const match of line . matchAll ( hyphenTermRgx ) ) {
2122 if ( match [ 0 ] . length > 3 ) {
22- if ( ! hyphenTerms . includes ( match [ 0 ] ) ) {
23- hyphenTerms . push ( match [ 0 ] )
23+ const termLower = match [ 0 ] . toLowerCase ( )
24+ if ( ! hyphenTerms . includes ( termLower ) ) {
25+ hyphenTerms . push ( termLower )
2426 }
2527 hyphenTermsOccurences . push ( {
26- term : match [ 0 ] ,
28+ term : termLower ,
2729 range : {
2830 startLineNumber : lineIdx + 1 ,
2931 startColumn : match . index + 1 ,
@@ -39,16 +41,17 @@ export function checkHyphenation (text) {
3941 for ( const [ lineIdx , line ] of textLines . entries ( ) ) {
4042 for ( const term of hyphenTerms ) {
4143 const altTerm = term . replaceAll ( '-' , '' )
42- const altTermRgx = new RegExp ( `(?:^|[>" ])${ altTerm } (?:[. "<]|$)` , 'gi' )
44+ const altTermRgx = new RegExp ( `(?:^|[>" ])( ${ altTerm } ) (?:[. "<]|$)` , 'gi' )
4345 for ( const match of line . matchAll ( altTermRgx ) ) {
46+ const matchLower = match [ 1 ] . toLowerCase ( )
4447 let occIdx = occurences . indexOf ( term )
4548 if ( occIdx < 0 ) {
4649 occIdx = occurences . push ( term ) - 1
4750 for ( const termOcc of hyphenTermsOccurences . filter ( t => t . term === term ) ) {
4851 decorations . push ( {
4952 options : {
5053 hoverMessage : {
51- value : `[${ occIdx } ] Inconsistent Hyphenation (Alternate of ${ altTerm } )`
54+ value : `[${ occIdx + 1 } ] Inconsistent Hyphenation (Alternate of ${ altTerm } )`
5255 } ,
5356 className : 'dec-warning' ,
5457 minimap : {
@@ -61,15 +64,20 @@ export function checkHyphenation (text) {
6164 details . push ( {
6265 key : crypto . randomUUID ( ) ,
6366 group : occIdx + 1 ,
64- message : `${ term } is alternate of ${ altTerm } ` ,
67+ message : `${ term } has alternate term(s) ` ,
6568 range : termOcc . range
6669 } )
6770 }
71+ if ( termCount [ term ] ) {
72+ termCount [ term ] ++
73+ } else {
74+ termCount [ term ] = 1
75+ }
6876 }
6977 decorations . push ( {
7078 options : {
7179 hoverMessage : {
72- value : `[${ occIdx } ] Inconsistent Hyphenation (Alternate of ${ term } )`
80+ value : `[${ occIdx + 1 } ] Inconsistent Hyphenation (Alternate of ${ term } )`
7381 } ,
7482 className : 'dec-warning' ,
7583 minimap : {
@@ -87,14 +95,19 @@ export function checkHyphenation (text) {
8795 details . push ( {
8896 key : crypto . randomUUID ( ) ,
8997 group : occIdx + 1 ,
90- message : `${ term } has alternate term(s) ` ,
98+ message : `${ matchLower } is alternate of ${ term } ` ,
9199 range : {
92100 startLineNumber : lineIdx + 1 ,
93101 startColumn : match . index + 2 ,
94102 endLineNumber : lineIdx + 1 ,
95103 endColumn : match . index + match [ 0 ] . length
96104 }
97105 } )
106+ if ( termCount [ matchLower ] ) {
107+ termCount [ matchLower ] ++
108+ } else {
109+ termCount [ matchLower ] = 1
110+ }
98111 }
99112 }
100113 }
@@ -103,7 +116,14 @@ export function checkHyphenation (text) {
103116 decorationsStore . get ( 'hyphenation' ) . set ( decorations )
104117
105118 return {
106- count : occurences . length ,
107- details : sortBy ( details , d => d . range . startLineNumber )
119+ count : details . length ,
120+ details : sortBy ( details , d => d . range . startLineNumber ) ,
121+ hasTextOutput : true ,
122+ getTextOutput : ( ) => {
123+ return `Hyphenation
124+ -------------
125+ ${ Object . entries ( termCount ) . map ( ( [ k , v ] ) => `${ k } (${ v } )` ) . join ( '\n' ) }
126+ `
127+ }
108128 }
109129}
0 commit comments