Add raw HTML draft editing to LaySite MCP
This commit is contained in:
@@ -18,13 +18,26 @@ final class PageHead
|
||||
'script' => ['src', 'type', 'async', 'defer', 'integrity', 'crossorigin', 'referrerpolicy'],
|
||||
];
|
||||
|
||||
public static function normalize(mixed $value): string
|
||||
public static function normalize(mixed $value, ?string $restrictScriptsTo = null): string
|
||||
{
|
||||
if (!is_string($value) || strlen($value) > self::MAX_LENGTH || !mb_check_encoding($value, 'UTF-8') || str_contains($value, "\0")) {
|
||||
throw new RuntimeException('Head 代码须使用 UTF-8,最多 32 KB。');
|
||||
}
|
||||
$value = trim($value);
|
||||
self::parse($value);
|
||||
$entries = self::parse($value);
|
||||
if ($restrictScriptsTo !== null) {
|
||||
$existing = self::parse($restrictScriptsTo);
|
||||
foreach ($entries as $entry) {
|
||||
if ($entry[0] !== 'script') {
|
||||
continue;
|
||||
}
|
||||
$index = array_search($entry, $existing, true);
|
||||
if ($index === false) {
|
||||
throw new RuntimeException('MCP 只能保留本页已有的脚本。请在管理后台添加或修改脚本。');
|
||||
}
|
||||
unset($existing[$index]);
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user