forked from laysense/laysite
Add page publication history and reusable blocks
This commit is contained in:
@@ -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 = [];
|
||||
|
||||
Reference in New Issue
Block a user