diff --git a/app/TrainingResource.php b/app/TrainingResource.php
index 66d653a93..7ea71a36e 100644
--- a/app/TrainingResource.php
+++ b/app/TrainingResource.php
@@ -276,10 +276,15 @@ public function renderedPdfLinksSectionForLocale(?string $locale = null): string
return '';
}
- $noteHtml = ''.e(__('training.discover_digital_key_one_pagers_note')).'';
+ $noteHtml = ''.e(__('training.discover_digital_key_one_pagers_note')).'';
if (str_contains($section, '[[key_one_pagers_locale_note]]')) {
- return str_replace('[[key_one_pagers_locale_note]]', $noteHtml, $section);
+ $section = str_replace('[[key_one_pagers_locale_note]]', $noteHtml, $section);
+ if ($this->slug === 'discover-digital-programme' && ! $this->hasKeyOnePagersHeading($section)) {
+ $section = '
'.$section;
+ }
+
+ return $section;
}
// Discover Digital: inject the note even when locale overrides omit the placeholder.
@@ -299,10 +304,15 @@ public function renderedPdfLinksSectionForLocale(?string $locale = null): string
}
}
- if (! str_contains(mb_strtolower($section), 'key one-pagers')) {
- return ''.$noteHtml.$section;
- }
+ // Always restore the heading when missing. Do not use a plain-text search for
+ // "key one-pagers" — the supporting-detail paragraph also mentions that phrase.
+ return ''.$noteHtml.$section;
+ }
- return $noteHtml.$section;
+ protected function hasKeyOnePagersHeading(string $html): bool
+ {
+ return preg_match('/]*\bid=(["\'])key-one-pagers\1[^>]*>/is', $html) === 1
+ || preg_match('/]*>\s*Key one-pagers\s*<\/h2>/is', $html) === 1
+ || preg_match('/(?:
]*>\s*)?\s*Key one-pagers\s*<\/strong>/is', $html) === 1;
}
}