$texy = new Texy(); $html = $texy->process($text);
Inheritance: use trait Strict
示例#1
0
文件: TexyMacro.php 项目: dg/texy
 public function texyClosed(Latte\MacroNode $node)
 {
     $text = $node->content;
     if (preg_match('#^([\\t ]*)\\S#m', $text, $m)) {
         // remove & restore indentation
         $text = str_replace(["\r", "\n" . $m[1]], ['', "\n"], $text);
         $this->texy->htmlOutputModule->baseIndent = strlen($m[1]);
     }
     $restore = [];
     $tokens = $node->tokenizer;
     while ($tokens->isNext()) {
         $module = $tokens->expectNextValue($tokens::T_SYMBOL) . 'Module';
         $tokens->expectNextValue('.');
         $prop = $tokens->expectNextValue($tokens::T_SYMBOL);
         $tokens->expectNextValue('=');
         $value = $tokens->expectNextValue($tokens::T_SYMBOL, $tokens::T_NUMBER);
         if ($tokens->isNext()) {
             $tokens->expectNextValue(',');
         }
         $restore[] = [&$this->texy->{$module}->{$prop}, $this->texy->{$module}->{$prop}];
         $this->texy->{$module}->{$prop} = $value;
     }
     $node->content = $this->texy->process($text);
     foreach ($restore as $info) {
         $info[0] = $info[1];
     }
 }
示例#2
0
 /**
  * @return Texy
  */
 public static function createTexy()
 {
     $texy = new Texy();
     $texy->encoding = 'utf-8';
     $texy->setOutputMode(Texy::HTML5);
     return $texy;
 }
 protected function createTemplate($class = NULL)
 {
     $template = parent::createTemplate($class);
     $template->addFilter('texy', function ($content) {
         return new \Latte\Runtime\Html($this->texy->process($content));
     });
     $this->registerTexyMacros($this->texy);
     return $template;
 }
示例#4
0
 public function beforeRender()
 {
     //nastaveni spravne cesty k obrazkum pro Texy
     $this->texy->imageModule->root = $this->template->basePath . '/images/';
     $this->texy->setOutputMode(\Texy\Texy::HTML5);
     $this->texy->figureModule->leftClass = 'pull-left';
     $this->texy->figureModule->rightClass = 'pull-right';
     $this->texy->imageModule->leftClass = 'pull-left';
     $this->texy->imageModule->rightClass = 'pull-right';
     $this->template->today = new \Nette\Utils\DateTime();
 }
示例#5
0
文件: Texy.php 项目: fvozar/images
 /**
  * @param \Texy|\Texy\Texy $texy
  * @param ImagePipe $imagePipe
  */
 public static function register($texy, ImagePipe $imagePipe)
 {
     if (!$texy instanceof \Texy && !$texy instanceof \Texy\Texy) {
         throw new \InvalidArgumentException('The $texy parameter is not instance of Texy or Texy\\Texy');
     }
     $texy->addHandler("image", function ($invocation, $image, $link) use($imagePipe) {
         if (!$invocation instanceof \TexyHandlerInvocation && !$invocation instanceof \Texy\HandlerInvocation) {
             throw new \InvalidArgumentException('The $invocation parameter is not instance of TexyHandlerInvocation or Texy\\HandlerInvocation');
         }
         if (!$image instanceof \TexyImage && !$image instanceof \Texy\Image) {
             throw new \InvalidArgumentException('The $image parameter is not instance of TexyImage or Texy\\Image');
         }
         $arguments = Helpers::prepareMacroArguments($image->URL);
         try {
             $image->URL = $imagePipe->setNamespace($arguments["namespace"])->request($arguments["name"], $arguments["size"], $arguments["flags"], TRUE);
         } catch (FileNotFoundException $e) {
             $image->URL = $arguments["name"];
             if (!empty($arguments["size"])) {
                 list($image->width, $image->height) = explode("x", $arguments["size"]);
             }
         }
         return $invocation->proceed($image, $link);
     });
 }
示例#6
0
 public function renderEdit($place_id)
 {
     $place = $this->context->createServicePlaces()->wherePrimary($place_id)->fetch();
     $tx = new Texy();
     $tx->alignClasses['left'] = 'fl';
     $tx->alignClasses['right'] = 'fr';
     $tx->imageModule->root = $this->getHttpRequest()->url->baseUrl;
     $tx->imageModule->fileRoot = $this->getHttpRequest()->url->baseUrl;
     $tx->imageModule->linkedRoot = $this->getHttpRequest()->url->baseUrl;
     $tx->linkModule->root = $this->getHttpRequest()->url->baseUrl;
     $tx->headingModule->top = 4;
     $pl = (array) $place->toArray();
     $pl['description'] = $tx->process($pl['description']);
     $this->template->place = $place;
     $this->template->new = false;
     $this['form']->setDefaults($pl);
     $this['form']['categories']->setDefaultValue($place->related('subject_x_category')->fetchPairs('category_id', 'category_id'));
 }
示例#7
0
 public function blockHandler($invocation, $blocktype, $content, $lang, $modifier)
 {
     if ($blocktype !== 'block/code') {
         return $invocation->proceed();
         //vstup se nebude zpracovavat
     }
     $highlighter = new \FSHL\Highlighter(new \FSHL\Output\Html(), \FSHL\Highlighter::OPTION_TAB_INDENT);
     $texy = $invocation->getTexy();
     $content = \Texy\Texy::outdent($content);
     //Set correct lexer:
     $lang = $lang ?: '';
     switch (strtoupper($lang)) {
         case 'C':
         case 'CPP':
             $lexer = new \FSHL\Lexer\Cpp();
             break;
         case 'CSS':
             $lexer = new \FSHL\Lexer\Css();
             break;
         case 'HTML':
             $lexer = new \FSHL\Lexer\Html();
             break;
             //HtmlOnly lexer
         //HtmlOnly lexer
         case 'JAVA':
             $lexer = new \FSHL\Lexer\Java();
             break;
         case 'JS':
         case 'JAVASCRIPT':
             $lexer = new \FSHL\Lexer\Javascript();
             break;
         case 'NEON':
             $lexer = new \FSHL\Lexer\Neon();
             break;
         case 'PHP':
             $lexer = new \FSHL\Lexer\Php();
             break;
         case 'PYTHON':
             $lexer = new \FSHL\Lexer\Python();
             break;
         case 'SQL':
             $lexer = new \FSHL\Lexer\Sql();
             break;
         case 'TEX':
             $lexer = new \App\Texy\Tex();
             break;
         case 'TEXY':
             $lexer = new \FSHL\Lexer\Texy();
             break;
         default:
             $lexer = new \FSHL\Lexer\Minimal();
     }
     $content = $highlighter->highlight($content, $lexer);
     $content = $texy->protect($content, \Texy\Texy::CONTENT_BLOCK);
     $elPre = \Texy\HtmlElement::el('pre');
     if ($modifier) {
         $modifier->decorate($texy, $elPre);
     }
     $elPre->attrs['class'] = strtolower($lang);
     $elPre->create('code', $content);
     return $elPre;
 }