From: moodler Date: Thu, 23 Sep 2004 12:33:14 +0000 (+0000) Subject: Tidy filter from Hannes Gassert X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=e5912bca117b5c492feae765a4dbdfe1a6232b68;p=moodle.git Tidy filter from Hannes Gassert If you have Tidy installed as part of your PHP, you can use this filter to convert all user text into XHTML on the fly. --- diff --git a/filter/tidy/filter.php b/filter/tidy/filter.php new file mode 100644 index 0000000000..d96c0090c4 --- /dev/null +++ b/filter/tidy/filter.php @@ -0,0 +1,47 @@ + +* @param int course id +* @param string text to be filtered +*/ +function tidy_filter($courseid, $text) { + +/// Configuration for tidy. Feel free to tune for your needs, e.g. to allow +/// proprietary markup. + $tidyoptions = array( + 'output-xhtml' => true, + 'show-body-only' => true, + 'tidy-mark' => false, + 'drop-proprietary-attributes' => true, + 'drop-font-tags' => true, + 'drop-empty-paras' => true, + 'indent' => true, + 'quiet' => true, + ); + +/// Do a quick check using strpos to avoid unnecessary work + if (strpos($text, '<') === false) { + return $text; + } + + +/// If enabled: run tidy over the entire string + if (function_exists('tidy_repair_string')){ + $text = tidy_repair_string($text, $tidyoptions); + } + + return $text; +} +?>