Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
StyleCIBot committed Aug 5, 2022
1 parent 8bab89c commit 20d6865
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 57 deletions.
11 changes: 6 additions & 5 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/

namespace TheTurk\MathRen;

use Flarum\Api\Serializer\ForumSerializer;
use Flarum\Extend;

return [
(new Extend\Frontend('forum'))
->css(__DIR__ . '/less/forum.less')
->js(__DIR__ . '/js/dist/forum.js'),
->css(__DIR__.'/less/forum.less')
->js(__DIR__.'/js/dist/forum.js'),

(new Extend\Frontend('admin'))
->css(__DIR__ . '/less/admin.less')
->js(__DIR__ . '/js/dist/admin.js'),
->css(__DIR__.'/less/admin.less')
->js(__DIR__.'/js/dist/admin.js'),

(new Extend\Locales(__DIR__ . '/locale')),
(new Extend\Locales(__DIR__.'/locale')),

(new Extend\ApiSerializer(ForumSerializer::class))
->attributes(LoadSettings::class),
Expand Down
29 changes: 15 additions & 14 deletions src/ConfigureTextFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/

namespace TheTurk\MathRen;

use Illuminate\Support\Arr;
Expand Down Expand Up @@ -78,37 +79,37 @@ public function __invoke(Configurator $config)

if ($allowAsciiMath && ($delimiter['ascii'] === true)) {
$config->BBCodes->addCustom(
$delimiter['left'] . '{TEXT}' . $delimiter['right'],
$delimiter['left'].'{TEXT}'.$delimiter['right'],
'<span>
<xsl:attribute name="class">' . $classes[$className] . '</xsl:attribute>
<xsl:attribute name="data-s9e-livepreview-onupdate">if(typeof katex!==\'undefined\')katex.render((typeof ascii2tex!==\'undefined\') ? ascii2tex.parse(this.innerText) : this.innerText, this, ' . $options . ')</xsl:attribute>
<xsl:attribute name="class">'.$classes[$className].'</xsl:attribute>
<xsl:attribute name="data-s9e-livepreview-onupdate">if(typeof katex!==\'undefined\')katex.render((typeof ascii2tex!==\'undefined\') ? ascii2tex.parse(this.innerText) : this.innerText, this, '.$options.')</xsl:attribute>
<xsl:apply-templates/>
<script defer="" crossorigin="anonymous">
<xsl:attribute name="data-s9e-livepreview-onrender">if(typeof ascii2tex!==\'undefined\')this.parentNode.removeChild(this)</xsl:attribute>
<xsl:attribute name="integrity">' . $this->util->get('sri_asciimath2tex') . '</xsl:attribute>
<xsl:attribute name="integrity">'.$this->util->get('sri_asciimath2tex').'</xsl:attribute>
<xsl:attribute name="onload">window.ascii2tex=new AsciiMathParser()</xsl:attribute>
<xsl:attribute name="src">' . $this->util->get('cdn_asciimath2tex') . '</xsl:attribute>
<xsl:attribute name="src">'.$this->util->get('cdn_asciimath2tex').'</xsl:attribute>
</script>
<script defer="" crossorigin="anonymous">
<xsl:attribute name="data-s9e-livepreview-onrender">if(typeof katex!==\'undefined\')this.parentNode.removeChild(this)</xsl:attribute>
<xsl:attribute name="integrity">' . $this->util->get('sri_katex') . '</xsl:attribute>
<xsl:attribute name="onload">katex.render((typeof ascii2tex!==\'undefined\') ? ascii2tex.parse(this.parentNode.innerText) : this.parentNode.innerText, this.parentNode, ' . $options . ')</xsl:attribute>
<xsl:attribute name="src">' . $this->util->get('cdn_katex') . '</xsl:attribute>
<xsl:attribute name="integrity">'.$this->util->get('sri_katex').'</xsl:attribute>
<xsl:attribute name="onload">katex.render((typeof ascii2tex!==\'undefined\') ? ascii2tex.parse(this.parentNode.innerText) : this.parentNode.innerText, this.parentNode, '.$options.')</xsl:attribute>
<xsl:attribute name="src">'.$this->util->get('cdn_katex').'</xsl:attribute>
</script>
</span>'
);
} else {
$config->BBCodes->addCustom(
$delimiter['left'] . '{TEXT}' . $delimiter['right'],
$delimiter['left'].'{TEXT}'.$delimiter['right'],
'<span>
<xsl:attribute name="class">' . $classes[$className] . '</xsl:attribute>
<xsl:attribute name="data-s9e-livepreview-onupdate">if(typeof katex!==\'undefined\')katex.render(this.innerText, this, ' . $options . ')</xsl:attribute>
<xsl:attribute name="class">'.$classes[$className].'</xsl:attribute>
<xsl:attribute name="data-s9e-livepreview-onupdate">if(typeof katex!==\'undefined\')katex.render(this.innerText, this, '.$options.')</xsl:attribute>
<xsl:apply-templates/>
<script defer="" crossorigin="anonymous">
<xsl:attribute name="data-s9e-livepreview-onrender">if(typeof katex!==\'undefined\')this.parentNode.removeChild(this)</xsl:attribute>
<xsl:attribute name="integrity">' . $this->util->get('sri_katex') . '</xsl:attribute>
<xsl:attribute name="onload">katex.render(this.parentNode.innerText, this.parentNode, ' . $options . ')</xsl:attribute>
<xsl:attribute name="src">' . $this->util->get('cdn_katex') . '</xsl:attribute>
<xsl:attribute name="integrity">'.$this->util->get('sri_katex').'</xsl:attribute>
<xsl:attribute name="onload">katex.render(this.parentNode.innerText, this.parentNode, '.$options.')</xsl:attribute>
<xsl:attribute name="src">'.$this->util->get('cdn_katex').'</xsl:attribute>
</script>
</span>'
);
Expand Down
55 changes: 28 additions & 27 deletions src/Helpers/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/

namespace TheTurk\MathRen\Helpers;

use Flarum\Settings\SettingsRepositoryInterface;
Expand Down Expand Up @@ -42,7 +43,7 @@ public function __construct(SettingsRepositoryInterface $settings)
*/
public function get(string $key, string $default = ''): string
{
return $this->settings->get($this->prefix . $key, $default);
return $this->settings->get($this->prefix.$key, $default);
}

/**
Expand All @@ -56,15 +57,15 @@ public function get(string $key, string $default = ''): string
public function getKatexOptions(): array
{
return [
'fleqn' => \boolval($this->get('enable_fleqn')),
'leqno' => \boolval($this->get('enable_leqno')),
'output' => $this->get('output_mode'),
'throwOnError' => \boolval($this->get('throw_on_error')),
'errorColor' => $this->get('error_color'),
'fleqn' => \boolval($this->get('enable_fleqn')),
'leqno' => \boolval($this->get('enable_leqno')),
'output' => $this->get('output_mode'),
'throwOnError' => \boolval($this->get('throw_on_error')),
'errorColor' => $this->get('error_color'),
'minRuleThickness' => \floatval($this->get('min_rule_thickness')),
'maxSize' => \floatval($this->get('max_size')),
'maxExpand' => \intval($this->get('max_expand')),
'macros' => \json_decode('{' . $this->get('macros') . '}'),
'maxSize' => \floatval($this->get('max_size')),
'maxExpand' => \intval($this->get('max_expand')),
'macros' => \json_decode('{'.$this->get('macros').'}'),
'colorIsTextColor' => \boolval($this->get('color_is_text_color')),
];
}
Expand Down Expand Up @@ -93,13 +94,13 @@ public function getClasses(): array
private function _getDelimitersByType(): array
{
return [
'block' => $this->_commaToArray($this->get('block_delimiters')),
'blockAscii' => $this->_commaToArray($this->get('block_asciimath_delimiters')),
'inline' => $this->_commaToArray($this->get('inline_delimiters')),
'inlineAscii' => $this->_commaToArray($this->get('inline_asciimath_delimiters')),
'aliasBlock' => $this->_commaToArray($this->get('alias_block_delimiters')),
'aliasBlockAscii' => $this->_commaToArray($this->get('alias_block_asciimath_delimiters')),
'aliasInline' => $this->_commaToArray($this->get('alias_inline_delimiters')),
'block' => $this->_commaToArray($this->get('block_delimiters')),
'blockAscii' => $this->_commaToArray($this->get('block_asciimath_delimiters')),
'inline' => $this->_commaToArray($this->get('inline_delimiters')),
'inlineAscii' => $this->_commaToArray($this->get('inline_asciimath_delimiters')),
'aliasBlock' => $this->_commaToArray($this->get('alias_block_delimiters')),
'aliasBlockAscii' => $this->_commaToArray($this->get('alias_block_asciimath_delimiters')),
'aliasInline' => $this->_commaToArray($this->get('alias_inline_delimiters')),
'aliasInlineAscii' => $this->_commaToArray($this->get('alias_inline_asciimath_delimiters')),
];
}
Expand All @@ -110,10 +111,10 @@ private function _getDelimitersByType(): array
* [[left] => '[math]', [right] => '[/math]', [display] => true]
* ^ they're created by `$this->_setOptions();`.
*
* @param string $type The delimiter type that we're creating an array for.
* Accepted types are `bbcode` and `alias`. If not set,
* returning array will include all delimiters.
* @param bool $isAsciiMathDelimiter To check whether it's an AsciiMath delimiter.
* @param string $type The delimiter type that we're creating an array for.
* Accepted types are `bbcode` and `alias`. If not set,
* returning array will include all delimiters.
* @param bool $isAsciiMathDelimiter To check whether it's an AsciiMath delimiter.
*
* @return array
*/
Expand Down Expand Up @@ -169,10 +170,10 @@ public function getDelimitersWithOptions(string $type, bool $isAsciiMathDelimite
array_push(
$delimitersWithOptions,
[
'left' => '\\\begin{' . $environment . '}',
'right' => '\\\end{' . $environment . '}',
'left' => '\\\begin{'.$environment.'}',
'right' => '\\\end{'.$environment.'}',
'display' => true,
'ascii' => false
'ascii' => false,
]
);
}
Expand All @@ -189,7 +190,7 @@ public function getDelimitersWithOptions(string $type, bool $isAsciiMathDelimite
* also including the expression placeholder.
* i.e. `[math]%e%[/math]`
* @param bool $displayMode To check whether it's a block or inline delimiter.
* @param bool $asciiMath To check whether it's an AsciiMath delimiter.
* @param bool $asciiMath To check whether it's an AsciiMath delimiter.
*
* @return array
*/
Expand All @@ -206,10 +207,10 @@ private function _setOptions(string $syntax, bool $displayMode = false, bool $as
array_push(
$r,
[
'left' => $left,
'right' => $right,
'left' => $left,
'right' => $right,
'display' => $displayMode,
'ascii' => $asciiMath
'ascii' => $asciiMath,
]
);

Expand Down
23 changes: 12 additions & 11 deletions src/LoadSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/

namespace TheTurk\MathRen;

use Illuminate\Support\Arr;
Expand Down Expand Up @@ -69,25 +70,25 @@ public function __invoke(): array
}

$$explicitArray[] = [
'left' => Str::before($delimiter['left'], ']') . ':0' . ']',
'right' => Str::before($delimiter['right'], ']') . ':0' . ']',
'left' => Str::before($delimiter['left'], ']').':0'.']',
'right' => Str::before($delimiter['right'], ']').':0'.']',
'display' => $delimiter['display'],
'ascii' => $delimiter['ascii']
'ascii' => $delimiter['ascii'],
];
}

$explicitDelimiters = $allowAsciiMath ? \array_merge($explicitAsciiDelimiters, $explicitLatexDelimiters) : $explicitLatexDelimiters;

$settings = [
'mathren.allow_asciimath' => $allowAsciiMath,
'mathren.katex_options' => $this->util->getKatexOptions(),
'mathren.allow_asciimath' => $allowAsciiMath,
'mathren.katex_options' => $this->util->getKatexOptions(),
'mathren.enable_editor_buttons' => \boolval($this->util->get('enable_editor_buttons')),
'mathren.aliases_as_primary' => \boolval($this->util->get('aliases_as_primary')),
'mathren.enable_copy_tex' => \boolval($this->util->get('enable_copy_tex')),
'mathren.aliases_as_primary' => \boolval($this->util->get('aliases_as_primary')),
'mathren.enable_copy_tex' => \boolval($this->util->get('enable_copy_tex')),

// Get type-specific delimiters.
'mathren.bbcode_delimiters' => $bbCodeDelimiters,
'mathren.alias_delimiters' => $aliasDelimiters,
'mathren.bbcode_delimiters' => $bbCodeDelimiters,
'mathren.alias_delimiters' => $aliasDelimiters,
'mathren.explicit_bbcode_delimiters' => $explicitDelimiters,

// Set primary delimiters.
Expand Down Expand Up @@ -115,7 +116,7 @@ function ($val) {
function ($val) {
return $val['display'] === false;
}
)
),
];

if ($allowAsciiMath) {
Expand Down Expand Up @@ -143,7 +144,7 @@ function ($val) {
function ($val) {
return $val['display'] === false;
}
)
),
]);
}

Expand Down

0 comments on commit 20d6865

Please sign in to comment.