public static function Html($Mixed) {
      if (!is_string($Mixed)) {
         return self::To($Mixed, 'Html');
      } else {
         $IsHtml = strpos($Mixed, '<') !== FALSE
            || (bool)preg_match('/&#?[a-z0-9]{1,10};/i', $Mixed);

         if ($IsHtml) {
            // The text contains html and must be purified.

            $Formatter = Gdn::Factory('HtmlFormatter');
            if(is_null($Formatter)) {
               // If there is no HtmlFormatter then make sure that script injections won't work.
               return self::Display($Mixed);
            }

            // Allow the code tag to keep all enclosed html encoded.
            $Mixed = preg_replace(
               array('/<code([^>]*)>(.+?)<\/code>/sei'),
               array('\'<code\'.RemoveQuoteSlashes(\'\1\').\'>\'.htmlspecialchars(RemoveQuoteSlashes(\'\2\')).\'</code>\''),
               $Mixed
            );
            
            // Do HTML filtering before our special changes
            $Mixed = $Formatter->Format($Mixed);

            // Links
            $Mixed = Gdn_Format::Links($Mixed);
            // Mentions & Hashes
            $Mixed = Gdn_Format::Mentions($Mixed);

            // nl2br
            if(C('Garden.Format.ReplaceNewlines', TRUE)) {
               $Mixed = preg_replace("/(\015\012)|(\015)|(\012)/", "<br />", $Mixed);
               $Mixed = FixNl2Br($Mixed);
            }
            
            $Result = $Mixed;            

//            $Result = $Result.
//               "<h3>Html</h3><pre>".nl2br(htmlspecialchars(str_replace("<br />", "\n", $Mixed)))."</pre>".
//               "<h3>Formatted</h3><pre>".nl2br(htmlspecialchars(str_replace("<br />", "\n", $Result)))."</pre>";
         } else {
            // The text does not contain html and does not have to be purified.
            // This is an optimization because purifying is very slow and memory intense.
            $Result = htmlspecialchars($Mixed, ENT_NOQUOTES, 'UTF-8');
            $Result = Gdn_Format::Mentions($Result);
            $Result = Gdn_Format::Links($Result);
            if(C('Garden.Format.ReplaceNewlines', TRUE)) {
               $Result = preg_replace("/(\015\012)|(\015)|(\012)/", "<br />", $Result);
               $Result = FixNl2Br($Result);
            }
         }
         
         return $Result;
      }
   }