(content string)
| 332 | } |
| 333 | |
| 334 | func (f *SearchRefFilter) Process(content string) string { |
| 335 | content = f.buffer + content |
| 336 | f.buffer = "" |
| 337 | |
| 338 | if content == "" { |
| 339 | return "" |
| 340 | } |
| 341 | |
| 342 | content = searchRefPattern.ReplaceAllStringFunc(content, func(match string) string { |
| 343 | runes := []rune(match) |
| 344 | refID := string(runes[1 : len(runes)-1]) |
| 345 | if result, ok := f.searchResults[refID]; ok { |
| 346 | return fmt.Sprintf(`[\[%d\]](%s)`, result.Index, result.URL) |
| 347 | } |
| 348 | return "" |
| 349 | }) |
| 350 | |
| 351 | if content == "" { |
| 352 | return "" |
| 353 | } |
| 354 | |
| 355 | maxPrefixLen := 20 |
| 356 | if len(content) < maxPrefixLen { |
| 357 | maxPrefixLen = len(content) |
| 358 | } |
| 359 | |
| 360 | for i := 1; i <= maxPrefixLen; i++ { |
| 361 | suffix := content[len(content)-i:] |
| 362 | if searchRefPrefixPattern.MatchString(suffix) { |
| 363 | f.buffer = suffix |
| 364 | return content[:len(content)-i] |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | return content |
| 369 | } |
| 370 | |
| 371 | func (f *SearchRefFilter) Flush() string { |
| 372 | result := f.buffer |
no outgoing calls
no test coverage detected