From 171b4563a09ff7e43c01549dc3b0cb99031ce7b5 Mon Sep 17 00:00:00 2001 From: Jetha Chan Date: Fri, 17 Jul 2015 22:23:18 +0900 Subject: [PATCH 1/2] MDL-50868 weblib: add ruby support to purify_html --- lib/weblib.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/weblib.php b/lib/weblib.php index 696caa53e0c..dcae7f96f8c 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -1704,7 +1704,7 @@ function purify_html($text, $options = array()) { $config = HTMLPurifier_Config::createDefault(); $config->set('HTML.DefinitionID', 'moodlehtml'); - $config->set('HTML.DefinitionRev', 2); + $config->set('HTML.DefinitionRev', 3); $config->set('Cache.SerializerPath', $cachedir); $config->set('Cache.SerializerPermissions', $CFG->directorypermissions); $config->set('Core.NormalizeNewlines', false); @@ -1743,6 +1743,9 @@ function purify_html($text, $options = array()) { $def->addElement('algebra', 'Inline', 'Inline', array()); // Algebra syntax, equivalent to @@xx@@. $def->addElement('lang', 'Block', 'Flow', array(), array('lang'=>'CDATA')); // Original multilang style - only our hacked lang attribute. $def->addAttribute('span', 'xxxlang', 'CDATA'); // Current very problematic multilang. + + // Use the built-in Ruby module to add annotation support. + $def->manager->addModule(new HTMLPurifier_HTMLModule_Ruby()); } $purifier = new HTMLPurifier($config); From b42cb6793530be6c4ccd711ca98121c8baeb8715 Mon Sep 17 00:00:00 2001 From: Jetha Chan Date: Fri, 17 Jul 2015 22:37:01 +0900 Subject: [PATCH 2/2] MDL-50868 weblib: add unit test for ruby support --- lib/tests/weblib_test.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/tests/weblib_test.php b/lib/tests/weblib_test.php index 513ee7b43ba..460d7e45980 100644 --- a/lib/tests/weblib_test.php +++ b/lib/tests/weblib_test.php @@ -567,4 +567,19 @@ EXPECTED; $this->assertSame($expected, strip_pluginfile_content($source)); } + public function test_purify_html_ruby() { + + $this->resetAfterTest(); + + $ruby = + "

京都(きょうと)は" . + "日本(にほん)の" . + "(みやこ)です。

"; + $illegal = ''; + + $cleaned = purify_html($ruby . $illegal); + $this->assertEquals($ruby, $cleaned); + + } + }