1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-07 23:03:00 +03:00

Includes: Switched page to new system

- Added mulit-level depth parsing.
- Updating usage of HTML doc in page content to be efficient.
- Removed now redundant PageContentTest cases.
- Made some include system fixes based upon testing.
This commit is contained in:
Dan Brown
2023-11-27 19:54:47 +00:00
parent 4874dc1304
commit 71c93c8878
7 changed files with 60 additions and 148 deletions

View File

@@ -9,16 +9,10 @@ use DOMNodeList;
class HtmlContentFilter
{
/**
* Remove all the script elements from the given HTML.
* Remove all the script elements from the given HTML document.
*/
public static function removeScripts(string $html): string
public static function removeScriptsFromDocument(HtmlDocument $doc)
{
if (empty($html)) {
return $html;
}
$doc = new HtmlDocument($html);
// Remove standard script tags
$scriptElems = $doc->queryXPath('//script');
static::removeNodes($scriptElems);
@@ -53,6 +47,19 @@ class HtmlContentFilter
// Remove 'on*' attributes
$onAttributes = $doc->queryXPath('//@*[starts-with(name(), \'on\')]');
static::removeAttributes($onAttributes);
}
/**
* Remove scripts from the given HTML string.
*/
public static function removeScriptsFromHtmlString(string $html): string
{
if (empty($html)) {
return $html;
}
$doc = new HtmlDocument($html);
static::removeScriptsFromDocument($doc);
return $doc->getBodyInnerHtml();
}