Skip to content

Commit

Permalink
Updated s2_latex extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
parpalak committed Sep 25, 2023
1 parent fc5f313 commit b85df0b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
10 changes: 5 additions & 5 deletions _extensions/s2_latex/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
die;
}

function s2_encodeURIComponent($str)
function s2_encodeURIComponent(string $str): string
{
$revert = array('%21' => '!', '%2A' => '*', '%27' => "'", '%28' => '(', '%29' => ')');
return strtr(rawurlencode($str), $revert);
}

function s2_latex_make($text)
function s2_latex_make($text): string
{
return preg_replace_callback('#\\$\\$([^<>\\$]*)\\$\\$#Ss', function ($matches) {
$formula = str_replace(array('&nbsp;', '&lt;', '&gt;', '&amp;'), array(' ', '<', '>', '&'), $matches[1]);
return '<img border="0" style="vertical-align: middle;" src="//i.upmath.me/png/' . s2_htmlencode(s2_encodeURIComponent($formula)) . '" alt="' . s2_htmlencode($formula) . '" />';
return preg_replace_callback('#\\$\\$([^<$]*)\\$\\$#S', static function ($matches) {
$formula = str_replace(['&nbsp;', '&lt;', '&gt;', '&amp;'], [' ', '<', '>', '&'], $matches[1]);
return '<img border="0" style="vertical-align: middle;" src="//i.upmath.me/svg/' . s2_htmlencode(s2_encodeURIComponent($formula)) . '" alt="' . s2_htmlencode($formula) . '" />';
}, $text);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
* @license http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
* @package s2_latex
*
* @var \S2\Cms\Asset\AssetPack $assetPack
* @var AssetPack $assetPack
*/

use S2\Cms\Asset\AssetPack;

if (!defined('S2_ROOT')) {
die;
}

$assetPack->addHeadJs('//i.upmath.me/latex.js');
$assetPack->addJs('//i.upmath.me/latex.js', [AssetPack::OPTION_PRELOAD, AssetPack::OPTION_DEFER]);
8 changes: 4 additions & 4 deletions _extensions/s2_latex/hooks/pr_render_pre_get_content_4.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
* @package s2_latex
*/

if (!defined('S2_ROOT')) {
die;
if (!defined('S2_ROOT')) {
die;
}

require S2_ROOT.'/_extensions/s2_latex'.'/functions.php';
require S2_ROOT . '/_extensions/s2_latex/functions.php';

$content['rss_title'] = s2_latex_make($content['rss_title']);
$content['rss_title'] = s2_latex_make($content['rss_title']);
$content['rss_description'] = s2_latex_make($content['rss_description']);
6 changes: 3 additions & 3 deletions _extensions/s2_latex/hooks/pr_render_pre_item_render_4.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* @package s2_latex
*/

if (!defined('S2_ROOT')) {
die;
if (!defined('S2_ROOT')) {
die;
}

$item['title'] = s2_latex_make($item['title']);
$item['text'] = s2_latex_make($item['text']);
$item['text'] = s2_latex_make($item['text']);
6 changes: 3 additions & 3 deletions _extensions/s2_latex/lang/English.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

return array(
return [

'Comment syntax' => 'Latex formulae: <span>$$</span>f(x) = x^2-\sqrt{x}<span>$$</span> converts into $$f(x) = x^2-\sqrt{x}$$.<br />',
'Comment syntax' => 'Latex formulas: <span>$$</span>f(x) = x^2-\sqrt{x}<span>$$</span> converts into $$f(x) = x^2-\sqrt{x}$$.<br />',

);
];
6 changes: 3 additions & 3 deletions _extensions/s2_latex/manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
/**
* LaTeX
*
* Integrates site with tex.s2cms.ru service
* Integrates site with i.upmath.me service
*
* @copyright (C) 2011-2014 Roman Parpalak
* @copyright (C) 2011-2023 Roman Parpalak
* @license http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
* @package s2_latex
*/
Expand All @@ -16,7 +16,7 @@
<id>s2_latex</id>
<title>LaTeX</title>
<version>2.0dev</version>
<description>Allows to write LaTeX formulae.</description>
<description>Allows to write LaTeX formulas.</description>
<author>Roman Parpalak</author>

<minversion>2.0dev</minversion>
Expand Down

0 comments on commit b85df0b

Please sign in to comment.