mirror of
https://github.com/flarum/core.git
synced 2025-08-03 23:17:43 +02:00
Allow formatter to be used for things other than post formatting
This commit is contained in:
@@ -69,17 +69,18 @@ class Formatter
|
||||
});
|
||||
}
|
||||
|
||||
protected function getParser(CommentPost $post)
|
||||
protected function getParser($context = null)
|
||||
{
|
||||
$parser = $this->getComponent('parser');
|
||||
$parser->registeredVars['post'] = $post;
|
||||
|
||||
event(new FormatterParser($parser, $post));
|
||||
$parser->registeredVars['context'] = $context;
|
||||
|
||||
event(new FormatterParser($parser, $context));
|
||||
|
||||
return $parser;
|
||||
}
|
||||
|
||||
protected function getRenderer(CommentPost $post)
|
||||
protected function getRenderer($context = null)
|
||||
{
|
||||
spl_autoload_register(function ($class) {
|
||||
if (file_exists($file = storage_path() . '/app/' . $class . '.php')) {
|
||||
@@ -89,7 +90,7 @@ class Formatter
|
||||
|
||||
$renderer = $this->getComponent('renderer');
|
||||
|
||||
event(new FormatterRenderer($renderer, $post));
|
||||
event(new FormatterRenderer($renderer, $context));
|
||||
|
||||
return $renderer;
|
||||
}
|
||||
@@ -109,16 +110,16 @@ class Formatter
|
||||
])['js'];
|
||||
}
|
||||
|
||||
public function parse($text, CommentPost $post)
|
||||
public function parse($text, $context = null)
|
||||
{
|
||||
$parser = $this->getParser($post);
|
||||
$parser = $this->getParser($context);
|
||||
|
||||
return $parser->parse($text);
|
||||
}
|
||||
|
||||
public function render($xml, CommentPost $post)
|
||||
public function render($xml, $context = null)
|
||||
{
|
||||
$renderer = $this->getRenderer($post);
|
||||
$renderer = $this->getRenderer($context);
|
||||
|
||||
return $renderer->render($xml);
|
||||
}
|
||||
|
Reference in New Issue
Block a user