MathjaxFilter.php in MathJax: LaTeX for Drupal 8.2
File
src/Plugin/Filter/MathjaxFilter.php
View source
<?php
namespace Drupal\mathjax\Plugin\Filter;
use Drupal\filter\Plugin\FilterBase;
use Drupal\filter\FilterProcessResult;
use Drupal\Core\Url;
class MathjaxFilter extends FilterBase {
public function process($text, $langcode) {
$wrapped = strip_tags($text) !== 'TEST' ? '<div class="tex2jax_process">' . $text . '</div>' : $text;
$result = new FilterProcessResult($wrapped);
$config = \Drupal::config('mathjax.settings');
$config_type = $config
->get('config_type');
if ($config_type == 0) {
$result
->setAttachments([
'library' => [
'mathjax/config',
'mathjax/source',
'mathjax/setup',
],
'drupalSettings' => [
'mathjax' => [
'config_type' => $config_type,
'config' => json_decode($config
->get('default_config_string')),
],
],
]);
}
return $result;
}
public function tips($long = FALSE) {
return $this
->t('<span class="tex2jax_ignore">Mathematics inside the <a href=":url">configured delimiters</a> is
rendered by MathJax. The default math delimiters are $$...$$ and \\[...\\] for
displayed mathematics, and $...$ and \\(...\\) for in-line mathematics.</span>', array(
':url' => Url::fromRoute('mathjax.settings')
->toString(),
));
}
}