OSDN Git Service

Import current code.
[osdn-codes/wiki-parser.git] / sfjp / wiki / processor / auto.php
1 <?php
2 namespace sfjp\Wiki\Processor;
3 class Auto extends Base {
4         public function process($text) {
5                 $match = null;
6                 $typemap = array();
7                 if (preg_match('/\A#!\/\S+\/(?:env\s+)?(ada|asm|asw|bash|csh|perl|python|ruby|sh|tcsh|zsh|php)/',
8                                $text, $match)) {
9                         $type = array_key_exists($match[1], $typemap) ? $typemap[$match[1]] : $match[1];
10                         $p = new Code(array($type));
11                 } else {
12                         $p = new Pre();
13                 }
14                 $p->setContext($this->getContext());
15                 $p->setFormatter($this->getFormatter());
16                 $this->formatted_text = $p->process($text)->getFormattedText();
17                 if (!$this->hasContext("parent_processor"))
18                         $this->formatted_text .= $this->getFormatter()->cleanup();
19                 return $this;
20         }
21 }