3 namespace BookStack\Entities\Tools;
5 use BookStack\Util\HtmlDocument;
8 class PageIncludeContent
10 protected static array $topLevelTags = ['table', 'ul', 'ol', 'pre'];
15 protected array $contents = [];
17 protected bool $isTopLevel = false;
19 public function __construct(
23 $this->parseHtml($html, $tag);
26 protected function parseHtml(string $html, PageIncludeTag $tag): void
32 $doc = new HtmlDocument($html);
34 $sectionId = $tag->getSectionId();
36 $this->contents = [...$doc->getBodyChildren()];
37 $this->isTopLevel = true;
41 $section = $doc->getElementById($sectionId);
46 $isTopLevel = in_array(strtolower($section->nodeName), static::$topLevelTags);
47 $this->isTopLevel = $isTopLevel;
48 $this->contents = $isTopLevel ? [$section] : [...$section->childNodes];
51 public function isInline(): bool
53 return !$this->isTopLevel;
56 public function isEmpty(): bool
58 return empty($this->contents);
64 public function toDomNodes(): array
66 return $this->contents;