Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| RemoveMarkdownHeaders | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| handle | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Filters\AIResponseFilter; |
| 4 | |
| 5 | use Closure; |
| 6 | |
| 7 | /** |
| 8 | * Removes markdown headers (# Title, ## Subtitle, etc.) |
| 9 | * while preserving social media hashtags (#Tag). |
| 10 | * |
| 11 | * The key distinction is requiring at least one space after the # characters. |
| 12 | * - "# Title" (header - removed) vs "#Opus46" (hashtag - preserved) |
| 13 | */ |
| 14 | class RemoveMarkdownHeaders |
| 15 | { |
| 16 | public function handle($data, Closure $next) |
| 17 | { |
| 18 | $data = preg_replace('/^\s*#+\s+(.*?)\s*$/m', '$1', $data); |
| 19 | |
| 20 | return $next($data); |
| 21 | } |
| 22 | } |