diff --git a/framework/core/composer.json b/framework/core/composer.json index e4b5e1e9e..6ebf501fc 100644 --- a/framework/core/composer.json +++ b/framework/core/composer.json @@ -50,7 +50,7 @@ "psr/http-message": "^1.0", "psr/http-server-handler": "^1.0", "psr/http-server-middleware": "^1.0", - "s9e/text-formatter": "^0.8.1", + "s9e/text-formatter": "^1.2.0", "symfony/config": "^3.3", "symfony/console": "^3.3", "symfony/http-foundation": "^3.3", diff --git a/framework/core/src/Formatter/Formatter.php b/framework/core/src/Formatter/Formatter.php index 18646742e..4cfc250fd 100644 --- a/framework/core/src/Formatter/Formatter.php +++ b/framework/core/src/Formatter/Formatter.php @@ -96,8 +96,7 @@ class Formatter */ public function flush() { - $this->cache->forget('flarum.formatter.parser'); - $this->cache->forget('flarum.formatter.renderer'); + $this->cache->forget('flarum.formatter'); } /** @@ -112,6 +111,13 @@ class Formatter $configurator->rendering->engine = 'PHP'; $configurator->rendering->engine->cacheDir = $this->cacheDir; + $configurator->enableJavaScript(); + $configurator->javascript->exportMethods = ['preview']; + + $minifier = $configurator->javascript->setMinifier('FirstAvailable'); + $minifier->add('MatthiasMullieMinify'); + $minifier->add('Noop'); + $configurator->Escaper; $configurator->Autoemail; $configurator->Autolink; @@ -142,16 +148,16 @@ class Formatter /** * Get a TextFormatter component. * - * @param string $name "renderer" or "parser" + * @param string $name "renderer" or "parser" or "js" * @return mixed */ protected function getComponent($name) { - $cacheKey = 'flarum.formatter.'.$name; - - return $this->cache->rememberForever($cacheKey, function () use ($name) { - return $this->getConfigurator()->finalize()[$name]; + $formatter = $this->cache->rememberForever('flarum.formatter', function () { + return $this->getConfigurator()->finalize(); }); + + return $formatter[$name]; } /** @@ -193,14 +199,6 @@ class Formatter */ public function getJs() { - $configurator = $this->getConfigurator(); - $configurator->enableJavaScript(); - $configurator->javascript->exportMethods = ['preview']; - $configurator->javascript->setMinifier('MatthiasMullieMinify'); - - return $configurator->finalize([ - 'returnParser' => false, - 'returnRenderer' => false - ])['js']; + return $this->getComponent('js'); } }