Ejemplo n.º 1
0
function display($file)
{
    global $bitter;
    if (isset($_REQUEST['file']) and $_REQUEST['file'] != $file) {
        return;
    }
    $language = array_pop(explode('.', $file));
    $data = file_get_contents('./examples/files/' . $file);
    if (!$bitter) {
        $bitter = new Bitter();
        $bitter->loadFormat('tabsize-4');
    }
    $bitter->loadLanguage($language);
    echo '<p><a href="?file=', $file, '">', $file, '</a></p>';
    try {
        $source = $bitter->process($data);
        echo '<pre class="language-', $language, '">', $source, '</pre>';
    } catch (Exception $error) {
        $message = $error->getMessage() . "\n\n" . $error->getTraceAsString();
        echo '<pre>', Bitter::encode($message), '</pre>';
    }
}
Ejemplo n.º 2
0
 public function getState($context)
 {
     $before = substr($context, 0, $this->position);
     $output = '';
     if ($this->capture instanceof BitterMatch) {
         $match = $this->capture->match($context);
         $context = substr($context, $this->position + strlen($match));
         if (!empty($this->rules)) {
             $output .= $this->process($match)->output;
         } else {
             $output .= Bitter::encode($match);
         }
     } else {
         if ($this->start instanceof BitterMatch) {
             $match = $this->start->match($context);
             $context = substr($context, $this->position + strlen($match));
             $result = $this->process($context);
             $output .= Bitter::tag('start')->wrap(Bitter::encode($match));
             $output .= $result->output;
             $context = $result->context;
         }
     }
     if ($this->tag instanceof BitterTag) {
         $output = $this->tag->wrap($output);
     }
     return (object) array('before' => Bitter::encode($before), 'value' => $output, 'context' => $context);
 }
Ejemplo n.º 3
0
<?php

//------------------------------------------------------------------------------
chdir('../');
require_once './bitter.php';
//------------------------------------------------------------------------------
header('content-type: text/plain; charset=utf8', true, 500);
try {
    $bitter = new Bitter();
    $bitter->loadLanguage($_REQUEST['language']);
    $bitter->loadFormat($_REQUEST['format']);
    $source = $bitter->process(stripslashes($_REQUEST['source']));
    header('content-type: text/plain; charset=utf8', true, 200);
    echo $source;
} catch (Exception $error) {
    if (isset($_REQUEST['debug']) and $_REQUEST['debug'] == 'true') {
        $message = $error->getMessage() . "\n\n" . $error->getTraceAsString();
        echo Bitter::encode($message);
    }
}
//------------------------------------------------------------------------------