1<?php
2/*
3 * Inline images: ![source](description "title")
4 */
5
6if(!defined('DOKU_INC')) die();
7if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
8require_once(DOKU_PLUGIN.'syntax.php');
9
10class syntax_plugin_markdowku_imagesinline extends DokuWiki_Syntax_Plugin {
11
12    function getType()  { return 'substition'; }
13    function getPType() { return 'block'; }
14    function getSort()  { return 101; }
15
16    function connectTo($mode) {
17        $this->nested_brackets_re =
18            str_repeat('(?>[^\[\]]+|\[', 6).
19            str_repeat('\])*', 6);
20        $this->Lexer->addSpecialPattern(
21            '\!\['.$this->nested_brackets_re.'\]\([ \t]*<?.+?>?[ \t]*(?:[\'"].*?[\'"])?\)',
22            $mode,
23            'plugin_markdowku_imagesinline');
24    }
25
26    function handle($match, $state, $pos, Doku_Handler $handler) {
27        if ($state == DOKU_LEXER_SPECIAL) {
28            $text = preg_match(
29                '/^\!\[('.$this->nested_brackets_re.')\]\([ \t]*<?(.+?)>?[ \t]*(?:[\'"](.*?)[\'"])?[ \t]*?\)$/',
30                $match,
31                $matches);
32            $target = $matches[2] == '' ? $matches[3] : $matches[2];
33            $title = $matches[1];
34            $handler->media($target.'|'.$title, $state, $pos);
35        }
36        return true;
37    }
38
39    function render($mode, Doku_Renderer $renderer, $data) {
40        return true;
41    }
42}
43//Setup VIM: ex: et ts=4 enc=utf-8 :
44