From 901fb4f2d0436f01f4603f91be56365eebdff3d3 Mon Sep 17 00:00:00 2001 From: Laurent David Date: Mon, 19 Jun 2023 08:45:50 +0200 Subject: [PATCH] MDL-78432 mod_label: Process markdown in label name * Process markdown and other allowed formats (see FORMAT_XXX) in get_label_name so it does not display it as a litteral string in the course index menu. --- mod/label/lib.php | 4 +++- mod/label/tests/lib_test.php | 27 ++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/mod/label/lib.php b/mod/label/lib.php index 1e7d194d1a2..a9258f8d459 100644 --- a/mod/label/lib.php +++ b/mod/label/lib.php @@ -34,7 +34,9 @@ define("LABEL_MAX_NAME_LENGTH", 50); * @return string */ function get_label_name($label) { - $name = html_to_text(format_string($label->intro, true)); + $context = context_module::instance($label->coursemodule); + $intro = format_text($label->intro, $label->introformat, ['filter' => false, 'context' => $context]); + $name = html_to_text(format_string($intro, true, ['context' => $context])); $name = preg_replace('/@@PLUGINFILE@@\/[[:^space:]]+/i', '', $name); // Remove double space and also nbsp; characters. $name = preg_replace('/\s+/u', ' ', $name); diff --git a/mod/label/tests/lib_test.php b/mod/label/tests/lib_test.php index 78811743d0a..90f16ed8464 100644 --- a/mod/label/tests/lib_test.php +++ b/mod/label/tests/lib_test.php @@ -289,7 +289,32 @@ class lib_test extends \advanced_testcase { 'content' => '', 'format' => FORMAT_HTML, 'expected' => 'Text and media area' - ] + ], + 'markdown' => [ + 'content' => "##Simple Title\n simple markdown format", + 'format' => FORMAT_MARKDOWN, + 'expected' => 'Simple Title simple markdown format' + ], + 'markdown with pluginfile' => [ + 'content' => "##Simple Title\n simple markdown format @@PLUGINFILE@@/moodle-hit-song.mp3", + 'format' => FORMAT_MARKDOWN, + 'expected' => 'Simple Title simple markdown format' + ], + 'plain text' => [ + 'content' => "Simple plain text @@PLUGINFILE@@/moodle-hit-song.mp3", + 'format' => FORMAT_PLAIN, + 'expected' => 'Simple plain text' + ], + 'moodle format text' => [ + 'content' => "Simple plain text @@PLUGINFILE@@/moodle-hit-song.mp3", + 'format' => FORMAT_MOODLE, + 'expected' => 'Simple plain text' + ], + 'html format text' => [ + 'content' => "

Simple plain title

with plain text

@@PLUGINFILE@@/moodle-hit-song.mp3", + 'format' => FORMAT_HTML, + 'expected' => 'Simple plain title with plain text' + ], ]; }