Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gjb2048 committed Sep 22, 2024
1 parent 47176ad commit da16337
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 62 deletions.
4 changes: 4 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Version Information
===================

Version 402.1.1 - In development
--------------------------------
1. M4.5 compatibility - https://moodledev.io/docs/4.5/devupdate#filter-plugins

Version 402.1.0 - 22/04/24
--------------------------
1. Improve settings UI.
Expand Down
86 changes: 86 additions & 0 deletions classes/text_filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace filter_synhi;

/**
* SynHi filter.
*
* @package filter_synhi
* @copyright &copy; 2020-onwards G J Barnard.
* @author G J Barnard - {@link http://moodle.org/user/profile.php?id=442195}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/

/**
* SynHi filter.
*
* @package filter_synhi
* @copyright &copy; 2020-onwards G J Barnard.
* @author G J Barnard - {@link http://moodle.org/user/profile.php?id=442195}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class text_filter extends \core_filters\text_filter {
/**
* @var bool $done - true if the engine has been initialised already.
*/
private static $done = false;

/**
* Filter the text.
*
* @param string $text to be processed by the text
* @param array $options filter options
*
* @return string text after processing.
*/
#[\Override]
public function filter($text, array $options = []) {
// Basic test to avoid work.
if (is_string($text)) {
global $PAGE;
if (
($PAGE->pagelayout != 'admin') &&
($this->context->contextlevel >= CONTEXT_COURSE) &&
($this->context->contextlevel <= CONTEXT_BLOCK)
) {
// Do a quick check to see if we have a tag.
$synpos = mb_strpos($text, '<code');
if ($synpos !== false) {
$config = get_config('filter_synhi');
if (!empty($config->engine)) {
$toolbox = \filter_synhi\toolbox::get_instance();
$markup = $toolbox->processtext($text, $synpos);
if ($markup !== false) {
$text = $markup;
} else {
global $OUTPUT;
$context = new stdClass();
$context->text = $text;
$text = $OUTPUT->render_from_template('filter_synhi/broken_markup', $context);
}
if (!self::$done) {
$toolbox->highlight_page($config);
self::$done = true;
}
}
}
}
}

return $text;
}
}
59 changes: 1 addition & 58 deletions filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,61 +23,4 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/

/**
* SynHi filter.
*
* @package filter_synhi
* @copyright &copy; 2020-onwards G J Barnard.
* @author G J Barnard - {@link http://moodle.org/user/profile.php?id=442195}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class filter_synhi extends moodle_text_filter {
/**
* @var bool $done - true if the engine has been initialised already.
*/
private static $done = false;

/**
* Filter the text.
*
* @param string $text to be processed by the text
* @param array $options filter options
*
* @return string text after processing.
*/
public function filter($text, array $options = []) {
// Basic test to avoid work.
if (is_string($text)) {
global $PAGE;
if (
($PAGE->pagelayout != 'admin') &&
($this->context->contextlevel >= CONTEXT_COURSE) &&
($this->context->contextlevel <= CONTEXT_BLOCK)
) {
// Do a quick check to see if we have a tag.
$synpos = mb_strpos($text, '<code');
if ($synpos !== false) {
$config = get_config('filter_synhi');
if (!empty($config->engine)) {
$toolbox = \filter_synhi\toolbox::get_instance();
$markup = $toolbox->processtext($text, $synpos);
if ($markup !== false) {
$text = $markup;
} else {
global $OUTPUT;
$context = new stdClass();
$context->text = $text;
$text = $OUTPUT->render_from_template('filter_synhi/broken_markup', $context);
}
if (!self::$done) {
$toolbox->highlight_page($config);
self::$done = true;
}
}
}
}
}

return $text;
}
}
class_alias(\filter_synhi\text_filter::class, \filter_synhi::class);
2 changes: 1 addition & 1 deletion settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
));

// Information.
$page->add(new \filter_synhi\admin_setting_information('filter_synhi/formatinformation', '', '', 402, 404));
$page->add(new \filter_synhi\admin_setting_information('filter_synhi/formatinformation', '', '', 402, 405));

// Readme.md.
$page->add(new \filter_synhi\admin_setting_markdown('filter_synhi/filterreadme', '', '', 'Readme.md', 'filter/synhi'));
Expand Down
6 changes: 3 additions & 3 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2024033000;
$plugin->version = 2024033001;
$plugin->requires = 2023042400.00; // 4.2 (Build: 20230424).
$plugin->supported = [402, 404];
$plugin->supported = [402, 405];
$plugin->component = 'filter_synhi';
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '402.1.0';
$plugin->release = '402.1.1';

0 comments on commit da16337

Please sign in to comment.