Add page publication history and reusable blocks

This commit is contained in:
2026-11-28 18:12:30 +08:00
parent 1c927d360c
commit 3b13f6533d
40 changed files with 1239 additions and 165 deletions
+13
View File
@@ -143,6 +143,19 @@ final class Html
return self::bodyMarkup($body);
}
public static function scopedFragment(string $html, string $scope): string
{
if ($html === '' || !preg_match('/\bid\s*=/i', $html)) {
return $html;
}
$document = new DOMDocument('1.0', 'UTF-8');
$document->loadHTML('<!doctype html><html><head><meta charset="UTF-8"></head><body>' . $html . '</body></html>', LIBXML_NOERROR | LIBXML_NOWARNING | LIBXML_NONET);
$body = $document->getElementsByTagName('body')->item(0);
self::scopeIds($body, $scope);
return self::bodyMarkup($body);
}
private static function scopeIds(DOMElement $body, string $prefix): void
{
$ids = [];