@@ -277,17 +277,17 @@ protected function inferTitle(string $path): string
277277 protected function extractH1 (string $ html ): ?string
278278 {
279279 $ dom = new \DOMDocument ;
280- // Use libxml internal error handling locally to avoid emitting
281- // warnings from malformed HTML. Save and restore the previous
282- // libxml error handling state so we don't affect global state
283- // used by the test harness (PHPUnit/Pest).
284- $ libxmlPrevious = libxml_use_internal_errors (true );
280+
281+ // Use output buffering to capture any libxml warnings without changing global error handling
282+ ob_start ();
283+ $ errorLevel = error_reporting (E_ALL & ~E_WARNING );
285284 try {
286285 $ dom ->loadHTML ('<?xml encoding="utf-8" ?> ' .$ html );
287286 } finally {
288- libxml_clear_errors ( );
289- libxml_use_internal_errors ( $ libxmlPrevious );
287+ error_reporting ( $ errorLevel );
288+ ob_end_clean ( );
290289 }
290+
291291 $ xpath = new \DOMXPath ($ dom );
292292
293293 $ node = $ xpath ->query ('//h1 ' )->item (0 );
@@ -321,17 +321,17 @@ protected function extractH1(string $html): ?string
321321 protected function injectHeadingIdsAndToc (string $ html ): array
322322 {
323323 $ dom = new \DOMDocument ;
324- // Use libxml internal error handling locally to avoid emitting
325- // warnings from malformed HTML. Save and restore the previous
326- // libxml error handling state so we don't affect global state
327- // used by the test harness (PHPUnit/Pest).
328- $ libxmlPrevious = libxml_use_internal_errors (true );
324+
325+ // Use output buffering to capture any libxml warnings without changing global error handling
326+ ob_start ();
327+ $ errorLevel = error_reporting (E_ALL & ~E_WARNING );
329328 try {
330329 $ dom ->loadHTML ('<?xml encoding="utf-8" ?> ' .$ html );
331330 } finally {
332- libxml_clear_errors ( );
333- libxml_use_internal_errors ( $ libxmlPrevious );
331+ error_reporting ( $ errorLevel );
332+ ob_end_clean ( );
334333 }
334+
335335 $ xpath = new \DOMXPath ($ dom );
336336
337337 $ toc = [];
0 commit comments