1<?php
2/*
3 * Italic text enclosed in underlines: _..._
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
10# Fix for Hogfather RC2 - see https://github.com/dwp-forge/columns/issues/5#issuecomment-638467603
11require_once(DOKU_INC.'inc/Parsing/Lexer/Lexer.php');
12
13class syntax_plugin_markdowku_italicunderline extends DokuWiki_Syntax_Plugin {
14
15    function getType()  { return 'formatting'; }
16    function getPType() { return 'normal'; }
17    function getSort()  { return 79; }
18    function getAllowedTypes() {
19        return Array('formatting', 'substition');
20    }
21
22    function connectTo($mode) {
23        $this->Lexer->addEntryPattern(
24            '(?<![\\\\])_(?![ _])(?=(?:(?!\n\n).)+?[^\\\\ _]_)',
25            $mode,
26            'plugin_markdowku_italicunderline');
27//        $this->Lexer->addSpecialPattern(
28//            '\w+_\w+_\w[\w_]*',
29//            $mode,
30//            'plugin_markdowku_italicunderline');
31    }
32
33    function postConnect() {
34        $this->Lexer->addExitPattern(
35            '(?<![\\\\_ ])_',
36            'plugin_markdowku_italicunderline');
37    }
38
39    function handle($match, $state, $pos, Doku_Handler $handler) {
40        return array($state, $match);
41    }
42
43    function render($mode, Doku_Renderer $renderer, $data) {
44
45        if ($data[0] == DOKU_LEXER_ENTER)
46            $renderer->emphasis_open();
47        elseif ($data[0] == DOKU_LEXER_EXIT)
48            $renderer->emphasis_close();
49        elseif ($data[0] == DOKU_LEXER_UNMATCHED)
50            $renderer->cdata($data[1]);
51        elseif ($data[0] == DOKU_LEXER_SPECIAL)
52            $renderer->cdata($data[1]);
53
54        return true;
55    }
56}
57