1<?php
2/*
3 * Italic text enclosed by asterisks, i.e. *...*
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_italicasterisk 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_italicasterisk');
27    }
28
29    function postConnect() {
30        $this->Lexer->addExitPattern(
31            '(?<![\\\\* ])\*',
32            'plugin_markdowku_italicasterisk');
33    }
34
35    function handle($match, $state, $pos, Doku_Handler $handler) {
36        return array($state, $match);
37    }
38
39    function render($mode, Doku_Renderer $renderer, $data) {
40        if ($data[0] == DOKU_LEXER_ENTER)
41            $renderer->emphasis_open();
42        elseif ($data[0] == DOKU_LEXER_EXIT)
43            $renderer->emphasis_close();
44        else
45            $renderer->cdata($data[1]);
46
47        return true;
48    }
49}
50