+ /**
+ * Escape script tags within HTML content.
+ * @param string $html
+ * @return mixed
+ */
+ protected function escapeScripts(string $html)
+ {
+ $scriptSearchRegex = '/<script.*?>.*?<\/script>/ms';
+ $matches = [];
+ preg_match_all($scriptSearchRegex, $html, $matches);
+ if (count($matches) === 0) {
+ return $html;
+ }
+
+ foreach ($matches[0] as $match) {
+ $html = str_replace($match, htmlentities($match), $html);
+ }
+ return $html;
+ }
+
+ /**
+ * Get the plain text version of a page's content.
+ * @param Page $page
+ * @return string
+ */
+ public function pageToPlainText(Page $page)
+ {
+ $html = $this->renderPage($page);
+ return strip_tags($html);
+ }
+