public function testAutoDetection()
 {
     $hl = new Highlight\Highlighter();
     $lngs = $hl->listLanguages();
     $hl->setAutodetectLanguages($lngs);
     $failed = array();
     foreach ($lngs as $language) {
         $path = __DIR__ . DIRECTORY_SEPARATOR . "detect" . DIRECTORY_SEPARATOR . $language;
         $this->assertTrue(file_exists($path));
         $d = dir($path);
         while (false !== ($entry = $d->read())) {
             if ($entry[0] !== ".") {
                 $filePath = $path . DIRECTORY_SEPARATOR . $entry;
                 $content = file_get_contents($filePath);
                 $expected = $language;
                 $r = $hl->highlightAuto($content);
                 $actual = $r->language;
                 if ($expected !== $actual) {
                     $failed[] = "{$expected} was detected as {$actual}";
                 }
             }
         }
         $d->close();
     }
     $this->assertEquals(array(), $failed);
 }
Ejemplo n.º 2
0
</span>
                                        </div>
                                        <div class="col-md-2 voting">
                                            <div class="pull-right">
                                                <span class="votes votes-up">0</span> <i class="thumbs-up"></i>
                                                <span class="votes votes-down">0</span> <i class="thumbs-down"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="comment-body">
                                    <div class="text">
                                        <?php 
        $pre_processed_text = \yii\helpers\Markdown::process($comment->text);
        $highlighter = new \Highlight\Highlighter();
        $highlighter->setAutodetectLanguages(array("php", "javascript", "html"));
        $matches = array();
        $pattern = "/<code>(.*?)<\\/code>/is";
        preg_match_all($pattern, $pre_processed_text, $matches);
        if (count($matches) > 0) {
            foreach ($matches[1] as $match) {
                $processed = $highlighter->highlightAuto(html_entity_decode($match));
                $pre_processed_text = str_replace($match, $processed->value, $pre_processed_text);
                $pre_processed_text = str_replace('<code>', '<pre><code class="hljs ' . $processed->language . '">', $pre_processed_text);
                $pre_processed_text = str_replace('</code>', '</code></pre>', $pre_processed_text);
            }
        }
        echo $pre_processed_text;
        ?>
                                    </div>
                                </div>
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
$start = microtime(true);
require_once "../Highlight/Autoloader.php";
spl_autoload_register("Highlight\\Autoloader::load");
$hl = new Highlight\Highlighter();
$hl->setAutodetectLanguages($hl->listLanguages());
?>
<html>
  <head>
    <link rel="stylesheet" type="text/css" href="../styles/default.css">
    <script src="highlight.pack.js"></script>
    <script>
        
function testDetection() {

    var table = document.getElementById('test');
    var rws = table.getElementsByTagName('TR');

    for (var i = 1; i < rws.length; i++) {
        var tds = rws[i].getElementsByTagName('TD');