1<?php
2/*
3 * References for links or images, i.e.
4 *  [id]: http://example.com
5 */
6
7if(!defined('DOKU_INC')) die();
8if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
9require_once(DOKU_PLUGIN.'syntax.php');
10
11class syntax_plugin_markdowku_references extends DokuWiki_Syntax_Plugin {
12
13    function getType()  { return 'substition'; }
14    function getPType() { return 'normal'; }
15    function getSort()  { return 100; }
16
17    function connectTo($mode) {
18        $this->Lexer->addSpecialPattern(
19            '\n[ ]{0,3}\[[^\n]+?\]:[ \t]*\n?[ \t]*<?\S+?>?[ \t]*\n?[ \t]*(?:(?<=\s)["(].+?[")][\t]*)?(?=\n)',
20            $mode,
21            'plugin_markdowku_references');
22    }
23
24    function handle($match, $state, $pos, Doku_Handler $handler) {
25        return array($state, $match);
26    }
27
28    function render($mode, Doku_Renderer $renderer, $data) {
29        if ($mode != 'metadata')
30            return false;
31
32        preg_match(
33                '/\[(.+)\]:[ \t]*\n?[ \t]*<?(\S+)>?[ \t]*\n?[ \t]*(?:(?<=\s)["(](.+?)[")][\t]*)?/',
34                $data[1],
35                $matches);
36        $key = 'markdowku_references_'.preg_replace("/ /", ".", $matches[1]);
37        $renderer->meta[$key] = $matches[2];
38        return true;
39    }
40}
41//Setup VIM: ex: et ts=4 enc=utf-8 :
42