@@ -39,7 +39,14 @@ public function __construct(
3939 public function setNewHTML (string $ html , User $ updater ): void
4040 {
4141 $ html = $ this ->extractBase64ImagesFromHtml ($ html , $ updater );
42- $ this ->page ->html = $ this ->formatHtml ($ html );
42+ $ html = $ this ->formatHtml ($ html );
43+
44+ $ themeResult = Theme::dispatch (ThemeEvents::PAGE_CONTENT_PRE_STORE , $ html , $ this ->page );
45+ if (is_string ($ themeResult )) {
46+ $ html = $ themeResult ;
47+ }
48+
49+ $ this ->page ->html = $ html ;
4350 $ this ->page ->text = $ this ->toPlainText ();
4451 $ this ->page ->markdown = '' ;
4552 }
@@ -52,7 +59,14 @@ public function setNewMarkdown(string $markdown, User $updater): void
5259 $ markdown = $ this ->extractBase64ImagesFromMarkdown ($ markdown , $ updater );
5360 $ this ->page ->markdown = $ markdown ;
5461 $ html = (new MarkdownToHtml ($ markdown ))->convert ();
55- $ this ->page ->html = $ this ->formatHtml ($ html );
62+ $ html = $ this ->formatHtml ($ html );
63+
64+ $ themeResult = Theme::dispatch (ThemeEvents::PAGE_CONTENT_PRE_STORE , $ html , $ this ->page );
65+ if (is_string ($ themeResult )) {
66+ $ html = $ themeResult ;
67+ }
68+
69+ $ this ->page ->html = $ html ;
5670 $ this ->page ->text = $ this ->toPlainText ();
5771 }
5872
@@ -81,7 +95,7 @@ protected function extractBase64ImagesFromHtml(string $htmlText, User $updater):
8195
8296 /**
8397 * Convert all inline base64 content to uploaded image files.
84- * Regex is used to locate the start of data-uri definitions then
98+ * Regex is used to locate the start of data-uri definitions, then
8599 * manual looping over content is done to parse the whole data uri.
86100 * Attempting to capture the whole data uri using regex can cause PHP
87101 * PCRE limits to be hit with larger, multi-MB, files.
@@ -301,7 +315,7 @@ public function render(bool $blankIncludes = false): string
301315 $ html = $ this ->page ->html ?? '' ;
302316
303317 if (empty ($ html )) {
304- return $ html ;
318+ return $ this -> handlePostRender ( '' ) ;
305319 }
306320
307321 $ doc = new HtmlDocument ($ html );
@@ -322,7 +336,7 @@ public function render(bool $blankIncludes = false): string
322336 $ cacheKey = $ this ->getContentCacheKey ($ doc ->getBodyInnerHtml ());
323337 $ cached = cache ()->get ($ cacheKey , null );
324338 if ($ cached !== null ) {
325- return $ cached ;
339+ return $ this -> handlePostRender ( $ cached) ;
326340 }
327341
328342 $ filterConfig = HtmlContentFilterConfig::fromConfigString (config ('app.content_filtering ' ));
@@ -332,7 +346,13 @@ public function render(bool $blankIncludes = false): string
332346 $ cacheTime = 86400 * 7 ; // 1 week
333347 cache ()->put ($ cacheKey , $ filtered , $ cacheTime );
334348
335- return $ filtered ;
349+ return $ this ->handlePostRender ($ filtered );
350+ }
351+
352+ protected function handlePostRender (string $ html ): string
353+ {
354+ $ themeResult = Theme::dispatch (ThemeEvents::PAGE_CONTENT_POST_RENDER , $ html , $ this ->page );
355+ return is_string ($ themeResult ) ? $ themeResult : $ html ;
336356 }
337357
338358 protected function getContentCacheKey (string $ html ): string
0 commit comments