From e5912bca117b5c492feae765a4dbdfe1a6232b68 Mon Sep 17 00:00:00 2001 From: moodler Date: Thu, 23 Sep 2004 12:33:14 +0000 Subject: [PATCH] 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. --- filter/tidy/filter.php | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 filter/tidy/filter.php 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; +} +?> -- 2.39.5