Example #1
0
    /**
     * Handle the match
     */
    function handle($match, $state, $pos, Doku_Handler $handler){
        global $conf;
        switch ($state) {
            case DOKU_LEXER_ENTER:
            case DOKU_LEXER_SPECIAL:
                $data = strtolower(trim(substr($match,strpos($match,' '),-1)," \t\n/"));
                return array($state, $data);

            case DOKU_LEXER_UNMATCHED:
                $handler->_addCall('cdata', array($match), $pos);
                break;

            case DOKU_LEXER_MATCHED:
                // we have a == header ==, use the core header() renderer
                // (copied from core header() in inc/parser/handler.php)
                $title = trim($match);
                $level = 7 - strspn($title,'=');
                if($level < 1) $level = 1;
                $title = trim($title,'=');
                $title = trim($title);

                $handler->_addCall('header',array($title,$level,$pos), $pos);
                // close the section edit the header could open
                if ($title && $level <= $conf['maxseclevel']) {
                    $handler->addPluginCall('wrap_closesection', array(), DOKU_LEXER_SPECIAL, $pos, '');
                }
                break;

            case DOKU_LEXER_EXIT:
                return array($state, '');
        }
        return false;
    }
Example #2
0
 function handle($match, $state, $pos, Doku_Handler $handler)
 {
     global $conf;
     // get level and title
     $title = trim($match);
     if ($this->getConf('precedence') == 'dokuwiki' && $title[strlen($title) - 1] == '=') {
         // DokuWiki
         $level = 7 - strspn($title, '=');
     } else {
         // Creole
         $level = strspn($title, '=');
     }
     if ($level < 1) {
         $level = 1;
     } elseif ($level > 5) {
         $level = 5;
     }
     $title = trim($title, '=');
     $title = trim($title);
     if ($handler->status['section']) {
         $handler->_addCall('section_close', array(), $pos);
     }
     $handler->_addCall('header', array($title, $level, $pos), $pos);
     $handler->_addCall('section_open', array($level), $pos);
     $handler->status['section'] = true;
     return true;
 }
Example #3
0
 function handle($match, $state, $pos, Doku_Handler $handler)
 {
     global $DOKU_PLUGINS;
     preg_match('/^\\n[ \\t]*>(?:[ \\t>]*>)?[ \\t]?/', $match, $quotearg);
     $quoteinarg = preg_replace('/^\\n[ \\t]*>(?:[ \\t>]*>)?[ \\t]?/', '', $match);
     if ($state == DOKU_LEXER_ENTER) {
         $ReWriter = new Doku_Handler_Markdown_Quote($handler->CallWriter);
         $handler->CallWriter =& $ReWriter;
         $handler->_addCall('quote_start', $quotearg, $pos);
     } elseif ($state == DOKU_LEXER_EXIT) {
         $handler->_addCall('quote_end', array(), $pos);
         $handler->CallWriter->process();
         $ReWriter =& $handler->CallWriter;
         $handler->CallWriter =& $ReWriter->CallWriter;
     }
     if ($quoteinarg == '') {
         $handler->_addCall('quote_newline', $quotearg, $pos);
         /* ATX headers (headeratx) */
     } elseif (preg_match('/^\\#{1,6}[ \\t]*.+?[ \\t]*\\#*/', $quoteinarg)) {
         $plugin =& plugin_load('syntax', 'markdowku_headeratx');
         $plugin->handle($quoteinarg, $state, $pos, $handler);
         /* Horizontal rulers (hr) */
     } elseif (preg_match('/[ ]{0,2}(?:[ ]?_[ ]?){3,}[ \\t]*/', $quoteinarg) or preg_match('/[ ]{0,2}(?:[ ]?-[ ]?){3,}[ \\t]*/', $quoteinarg) or preg_match('/[ ]{0,2}(?:[ ]?\\*[ ]?){3,}[ \\t]*/', $quoteinarg)) {
         $plugin =& plugin_load('syntax', 'markdowku_hr');
         $plugin->handle($quoteinarg, $state, $pos, $handler);
         /* Setext headers (headersetext) */
     } elseif (preg_match('/^[^\\n]+?[ \\t]*\\n[ \\t]*>(?:[ \\t>]*>)?[ \\t]?=+[ \\t]*/', $quoteinarg) or preg_match('/^[^\\n]+?[ \\t]*\\n[ \\t]*>(?:[ \\t>]*>)?[ \\t]?-+[ \\t]*/', $quoteinarg)) {
         $quoteinarg = preg_replace('/(?<=\\n)[ \\t]*>(?:[ \\t>]*>)?[ \\t]?/', '', $quoteinarg);
         $plugin =& plugin_load('syntax', 'markdowku_headersetext');
         $plugin->handle($quoteinarg, $state, $pos, $handler);
     } else {
         $handler->_addCall('cdata', array($quoteinarg), $pos);
     }
     return true;
 }
Example #4
0
 function handle($match, $state, $pos, Doku_Handler $handler)
 {
     global $conf;
     $title = trim($match);
     $level = strspn($title, '#');
     $title = trim($title, '#');
     $title = trim($title);
     if ($level < 1) {
         $level = 1;
     } elseif ($level > 6) {
         $level = 6;
     }
     if ($handler->status['section']) {
         $handler->_addCall('section_close', array(), $pos);
     }
     if ($level <= $conf['maxseclevel']) {
         $handler->status['section_edit_start'] = $pos;
         $handler->status['section_edit_level'] = $level;
         $handler->status['section_edit_title'] = $title;
     }
     $handler->_addCall('header', array($title, $level, $pos), $pos);
     $handler->_addCall('section_open', array($level), $pos);
     $handler->status['section'] = true;
     return true;
 }
 /**
  * Handle matches of the imagecarousel syntax
  *
  * @param string $match The match of the syntax
  * @param int    $state The state of the handler
  * @param int    $pos The position in the document
  * @param Doku_Handler    $handler The handler
  * @return array Data for the renderer
  */
 public function handle($match, $state, $pos, Doku_Handler &$handler)
 {
     $data = array();
     $data['state'] = $state;
     switch ($state) {
         case DOKU_LEXER_ENTER:
             $match = substr($match, 9, -1);
             // strip markup
             $flags = array_merge($this->getDefaultFlags(), $this->parseFlags($match));
             $flags = json_encode($flags);
             $data['flags'] = $flags;
             break;
         case DOKU_LEXER_UNMATCHED:
             if (trim($match) !== '') {
                 $handler->_addCall('cdata', array($match), $pos);
             }
             break;
         case DOKU_LEXER_EXIT:
             $this->first_item = false;
             break;
         case DOKU_LEXER_MATCHED:
             if ($match === "\n  *") {
                 if (!$this->first_item) {
                     $this->first_item = true;
                     $data['first_item'] = true;
                 }
             }
             break;
     }
     return $data;
 }
Example #6
0
 /**
  * Handle the match
  */
 function handle($match, $state, $pos, Doku_Handler $handler)
 {
     global $conf;
     switch ($state) {
         case DOKU_LEXER_ENTER:
             $data = strtolower(trim(substr($match, strpos($match, ' '), -1)));
             return array($state, $data);
         case DOKU_LEXER_UNMATCHED:
             // check if $match is a == header ==
             $headerMatch = preg_grep('/([ \\t]*={2,}[^\\n]+={2,}[ \\t]*(?=))/msSi', array($match));
             if (empty($headerMatch)) {
                 $handler->_addCall('cdata', array($match), $pos);
             } else {
                 // if it's a == header ==, use the core header() renderer
                 // (copied from core header() in inc/parser/handler.php)
                 $title = trim($match);
                 $level = 7 - strspn($title, '=');
                 if ($level < 1) {
                     $level = 1;
                 }
                 $title = trim($title, '=');
                 $title = trim($title);
                 $handler->_addCall('header', array($title, $level, $pos), $pos);
                 // close the section edit the header could open
                 if ($title && $level <= $conf['maxseclevel']) {
                     $handler->addPluginCall('wrap_closesection', array(), DOKU_LEXER_SPECIAL, $pos, '');
                 }
             }
             return false;
         case DOKU_LEXER_EXIT:
             return array($state, '');
     }
     return false;
 }
Example #7
0
 function handle($match, $state, $pos, Doku_Handler $handler)
 {
     if ($state == DOKU_LEXER_UNMATCHED) {
         $handler->_addCall('preformatted', array($match), $pos);
     }
     return true;
 }
Example #8
0
 function handle($match, $state, $pos, Doku_Handler $handler)
 {
     if ($state == DOKU_LEXER_SPECIAL) {
         $text = preg_match('/^\\!\\[(' . $this->nested_brackets_re . ')\\]\\([ \\t]*<?(.+?)>?[ \\t]*(?:[\'"](.*?)[\'"])?[ \\t]*?\\)$/', $match, $matches);
         $target = $matches[2] == '' ? $matches[3] : $matches[2];
         $title = $matches[1];
         $handler->media($target . '|' . $title, $state, $pos);
     }
     return true;
 }
Example #9
0
 function handle($match, $state, $pos, Doku_Handler $handler)
 {
     if (preg_match('/^<mailto:/', $match)) {
         $match = substr($match, 8, -1);
         $handler->_addCall('emaillink', array($match, NULL), $pos);
     } else {
         $match = substr($match, 1, -1);
         $handler->_addCall('externallink', array($match, NULL), $pos);
     }
     return true;
 }
Example #10
0
 /**
  * Handle the match
  */
 function handle($match, $state, $pos, Doku_Handler $handler)
 {
     switch ($state) {
         case DOKU_LEXER_ENTER:
             $data = strtolower(trim(substr($match, strpos($match, ' '), -1)));
             return array($state, $data);
         case DOKU_LEXER_UNMATCHED:
             $handler->_addCall('cdata', array($match), $pos);
             return false;
         case DOKU_LEXER_EXIT:
             return array($state, '');
     }
     return false;
 }
Example #11
0
 function handle($match, $state, $pos, Doku_Handler $handler)
 {
     switch ($state) {
         case DOKU_LEXER_ENTER:
             $handler->_addCall('monospace_open', array(), $pos);
             break;
         case DOKU_LEXER_UNMATCHED:
             $handler->_addCall('unformatted', array($match), $pos);
             break;
         case DOKU_LEXER_EXIT:
             $handler->_addCall('monospace_close', array(), $pos);
             break;
     }
     return true;
 }
 /**
  * Handle matches of the highlightjs syntax
  *
  * @param string $match The match of the syntax
  * @param int    $state The state of the handler
  * @param int    $pos The position in the document
  * @param Doku_Handler    $handler The handler
  * @return array Data for the renderer
  */
 public function handle($match, $state, $pos, Doku_Handler $handler)
 {
     $data = array();
     switch ($state) {
         case DOKU_LEXER_ENTER:
         case DOKU_LEXER_SPECIAL:
             $data = strtolower(trim(substr($match, strpos($match, ' '), -1), " \t\n/"));
             return array($state, $data);
         case DOKU_LEXER_UNMATCHED:
             $handler->_addCall('cdata', array($match), $pos);
             break;
         case DOKU_LEXER_EXIT:
             return array($state, '');
     }
     return false;
 }
Example #13
0
 function handle($match, $state, $pos, Doku_Handler $handler)
 {
     if (preg_match('/^\\n```([a-z0-9_]+)\\n/', $match, $matches) > 0) {
         $lang = $matches[1];
     } else {
         $lang = NULL;
     }
     $text = preg_replace('/^```[a-z0-9_]+\\n/m', '', $match);
     $text = preg_replace('/^```$/m', '', $text);
     if ($lang) {
         $handler->_addCall('file', array($text, $lang, 'snippet.' . $lang), $pos);
     } else {
         $handler->_addCall('code', array($text, $lang), $pos);
     }
     return true;
 }
Example #14
0
 function handle($match, $state, $pos, Doku_Handler $handler)
 {
     $title = preg_replace('/^\\n(.+?)[ \\t]*\\n.*/', '\\1', $match);
     $title = trim($title);
     if (preg_match('/^\\n(.+?)[ \\t]*\\n=/', $match)) {
         $level = 1;
     }
     if (preg_match('/^\\n(.+?)[ \\t]*\\n-/', $match)) {
         $level = 2;
     }
     if ($handler->status['section']) {
         $handler->_addCall('section_close', array(), $pos);
     }
     $handler->status['section_edit_start'] = $pos;
     $handler->status['section_edit_level'] = $level;
     $handler->status['section_edit_title'] = $title;
     $handler->_addCall('header', array($title, $level, $pos), $pos);
     $handler->_addCall('section_open', array($level), $pos);
     $handler->status['section'] = true;
     return true;
 }
Example #15
0
 function handle($match, $state, $pos, Doku_Handler $handler)
 {
     switch ($state) {
         case DOKU_LEXER_ENTER:
             $ReWriter = new Doku_Handler_Markdown_Ordered_List($handler->CallWriter);
             $handler->CallWriter =& $ReWriter;
             $handler->_addCall('list_open', array($match), $pos);
             break;
         case DOKU_LEXER_MATCHED:
             $handler->_addCall('list_item', array($match), $pos);
             break;
         case DOKU_LEXER_UNMATCHED:
             $handler->_addCall('cdata', array($match), $pos);
             break;
         case DOKU_LEXER_EXIT:
             $handler->_addCall('list_close', array(), $pos);
             $handler->CallWriter->process();
             $ReWriter =& $handler->CallWriter;
             $handler->CallWriter =& $ReWriter->CallWriter;
             break;
     }
     return true;
 }
Example #16
0
 function handle($match, $state, $pos, Doku_Handler $handler)
 {
     global $conf;
     switch ($state) {
         case DOKU_LEXER_ENTER:
             if ($this->getConf('monospace') == 'DokuWiki') {
                 $handler->_addCall('monospace_open', array(), $pos);
             } else {
                 return array($state);
             }
             break;
         case DOKU_LEXER_UNMATCHED:
             $handler->_addCall('cdata', array($match), $pos);
             break;
         case DOKU_LEXER_EXIT:
             if ($this->getConf('monospace') == 'DokuWiki') {
                 $handler->_addCall('monospace_close', array(), $pos);
             } else {
                 return array($state);
             }
             break;
     }
     return true;
 }
 function handle($match, $state, $pos, Doku_Handler $handler)
 {
     switch ($state) {
         case DOKU_LEXER_MATCHED:
             $title = trim($match);
             $level = 7 - strspn($title, '=');
             if ($level < 1) {
                 $level = 1;
             }
             $title = trim($title, '=');
             $title = trim($title);
             //if( $handler->status['section'] ) $handler->_addCall('section_close',array(), $pos);
             $handler->_addCall('header', array($title, $level, $pos), $pos);
             //$handler->_addCall('section_open',array($level),$pos);
             //$this->status['section'] = true;
             break;
         case DOKU_LEXER_ENTER:
             $attributes = array();
             $xml = simplexml_load_string(str_replace('>', '/>', $match));
             $tag = $xml->getName();
             foreach ($xml->attributes() as $key => $value) {
                 $attributes[$key] = (string) $value;
             }
             if ($tag == strtolower($tag)) {
                 $is_block = false;
             }
             if ($tag == strtoupper($tag)) {
                 $is_block = true;
             }
             return array($state, $match, $this->checkAttributes($attributes), $is_block);
         case DOKU_LEXER_UNMATCHED:
             $handler->_addCall('cdata', array($match), $pos);
             //return array($state, $match);
             break;
         case DOKU_LEXER_EXIT:
             return array($state, '');
     }
     return array();
 }
Example #18
0
 function handle($match, $state, $pos, Doku_Handler $handler)
 {
     switch ($state) {
         case DOKU_LEXER_ENTER:
             $ReWriter = new Doku_Handler_Preformatted($handler->CallWriter);
             $handler->CallWriter =& $ReWriter;
             $handler->_addCall('preformatted_start', array($match), $pos);
             break;
         case DOKU_LEXER_MATCHED:
             $handler->_addCall('preformatted_newline', array($match), $pos);
             break;
         case DOKU_LEXER_UNMATCHED:
             $handler->_addCall('preformatted_content', array($match), $pos);
             break;
         case DOKU_LEXER_EXIT:
             $handler->_addCall('preformatted_end', array(), $pos);
             $handler->_addCall('preformatted_content', array($match), $pos);
             $handler->CallWriter->process();
             $ReWriter =& $handler->CallWriter;
             $handler->CallWriter =& $ReWriter->CallWriter;
             break;
     }
     return true;
 }
Example #19
0
 function handle($match, $state, $pos, Doku_Handler $handler)
 {
     $handler->_addCall('hr', array(), $pos);
     return true;
 }
Example #20
0
 function handle($match, $state, $pos, Doku_Handler $handler)
 {
     switch ($state) {
         case DOKU_LEXER_ENTER:
             $ReWriter = new Doku_Handler_Table($handler->CallWriter);
             $handler->CallWriter =& $ReWriter;
             $handler->_addCall('table_start', array(), $pos);
             //$handler->_addCall('table_row', array(), $pos);
             if (trim($match) == '|=') {
                 $handler->_addCall('tableheader', array(), $pos);
             } else {
                 $handler->_addCall('tablecell', array(), $pos);
             }
             break;
         case DOKU_LEXER_EXIT:
             $handler->_addCall('table_end', array(), $pos);
             $handler->CallWriter->process();
             $ReWriter =& $handler->CallWriter;
             $handler->CallWriter =& $ReWriter->CallWriter;
             break;
         case DOKU_LEXER_UNMATCHED:
             if (trim($match) != '') {
                 $handler->_addCall('cdata', array($match), $pos);
             }
             break;
         case DOKU_LEXER_MATCHED:
             if ($match == ' ') {
                 $handler->_addCall('cdata', array($match), $pos);
             } else {
                 if (preg_match('/\\t+/', $match)) {
                     $handler->_addCall('table_align', array($match), $pos);
                 } else {
                     if (preg_match('/ {2,}/', $match)) {
                         $handler->_addCall('table_align', array($match), $pos);
                     } else {
                         if ($match == "\n|") {
                             $handler->_addCall('table_row', array(), $pos);
                             $handler->_addCall('tablecell', array(), $pos);
                         } else {
                             if ($match == "\n|=") {
                                 $handler->_addCall('table_row', array(), $pos);
                                 $handler->_addCall('tableheader', array(), $pos);
                             } else {
                                 if ($match == '|') {
                                     $handler->_addCall('tablecell', array(), $pos);
                                 } else {
                                     if ($match == '|=') {
                                         $handler->_addCall('tableheader', array(), $pos);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             break;
     }
     return true;
 }