diff --git a/app/TrainingResource.php b/app/TrainingResource.php index 86edd4852..0e39c8bc4 100644 --- a/app/TrainingResource.php +++ b/app/TrainingResource.php @@ -287,51 +287,44 @@ public function renderedPdfLinksSectionForLocale(?string $locale = null): string return $section; } - // Collapse any existing Key one-pagers title variants (h2 / strong / Trix wrappers) - // into a single h2, then place the locale note immediately after it. - $titlePattern = '/(?:<(?:div|p)[^>]*>\s*)?(?:
wrappers around strong/b title, allowing
inside
+ '/<(?:div|p)[^>]*>\s*<(?:strong|b)[^>]*>\s*Key one-pagers(?:\s|
)*<\/(?:strong|b)>\s*<\/(?:div|p)>/iu',
+ // bare Key one-pagers
+ '/<(?:strong|b)[^>]*>\s*Key one-pagers(?:\s|
)*<\/(?:strong|b)>/iu',
+ ];
- $afterFirst = substr($section, $pos + strlen($noteHtml));
- if (! str_contains($afterFirst, $noteHtml)) {
- return $section;
+ foreach ($patterns as $pattern) {
+ $html = preg_replace($pattern, '', $html) ?? $html;
}
- return substr($section, 0, $pos + strlen($noteHtml)).str_replace($noteHtml, '', $afterFirst);
+ return $html;
}
- protected function hasKeyOnePagersHeading(string $html): bool
+ /**
+ * Remove earlier auto-injected locale note spans (English or translated).
+ */
+ protected function stripInjectedKeyOnePagersNotes(string $html): string
{
- return preg_match('/