@@ -109,10 +109,11 @@ func (l *Linter) lintHTMLTokens(f *core.File, raw []byte, offset int) error { //
109109 txt , skip = clean (txt , attr , skip || skipClass , inline )
110110 // `clean` prefixes inline content with a space so it doesn't
111111 // fuse with the preceding text. When that content directly
112- // follows an opening bracket (e.g., a link inside parentheses,
113- // `([HNSW](...))`), the space is spurious and breaks patterns
114- // like `(ACRONYM)`. See #1056.
115- if strings .HasPrefix (txt , " " ) && endsWithOpenBracket (buf ) {
112+ // follows a tight boundary -- an opening bracket (a link in
113+ // parentheses, `([HNSW](...))`, #1056) or a dash
114+ // (`Triggers—**Article**`, #1029) -- the space is spurious and
115+ // produces false positives like ` —` / `( ACRONYM)`.
116+ if strings .HasPrefix (txt , " " ) && endsWithTightBoundary (buf ) {
116117 txt = txt [1 :]
117118 }
118119 buf .WriteString (txt )
@@ -230,16 +231,15 @@ func shouldBeSkipped(tagHistory []string, ext string) bool {
230231 return false
231232}
232233
233- // endsWithOpenBracket reports whether the buffer's last byte is an opening
234- // bracket, meaning inline content that follows it shouldn't be padded with a
235- // leading space. See #1056.
236- func endsWithOpenBracket (buf * bytes.Buffer ) bool {
237- b := buf .Bytes ()
238- if len (b ) == 0 {
239- return false
240- }
241- switch b [len (b )- 1 ] {
242- case '(' , '[' , '{' :
234+ // endsWithTightBoundary reports whether the buffer ends with a character that
235+ // binds tightly to what follows -- an opening bracket or a dash -- so inline
236+ // content placed after it shouldn't be padded with a leading space. Handles
237+ // "([HNSW](...))" (#1056) and "Triggers—**Article**" (#1029). We decode the
238+ // last rune because dashes are multi-byte.
239+ func endsWithTightBoundary (buf * bytes.Buffer ) bool {
240+ r , _ := utf8 .DecodeLastRune (buf .Bytes ())
241+ switch r {
242+ case '(' , '[' , '{' , '—' , '–' :
243243 return true
244244 default :
245245 return false
@@ -249,8 +249,10 @@ func endsWithOpenBracket(buf *bytes.Buffer) bool {
249249func clean (txt , attr string , skip , inline bool ) (string , bool ) {
250250 // Closing brackets are included so that inline content immediately
251251 // followed by one (e.g., a link inside parentheses) doesn't get a spurious
252- // space inserted before it -- "(HNSW)" rather than "(HNSW )". See #1056.
253- punct := []string {"." , "?" , "!" , "," , ":" , ";" , ")" , "]" , "}" }
252+ // space inserted before it -- "(HNSW)" rather than "(HNSW )" (#1056). Dashes
253+ // are included so text like "—This" right after a link isn't padded to
254+ // " —This" (#1029).
255+ punct := []string {"." , "?" , "!" , "," , ":" , ";" , ")" , "]" , "}" , "—" , "–" }
254256 first , _ := utf8 .DecodeRuneInString (txt )
255257 starter := core .StringInSlice (string (first ), punct ) && ! skip
256258
0 commit comments