xref: /dokuwiki/inc/Parsing/ParserMode/GfmHr.php (revision 3e6baeff313fa406e4d4b5dd2e5ab85ec7d7816d)
1*3e6baeffSAndreas Gohr<?php
2*3e6baeffSAndreas Gohr
3*3e6baeffSAndreas Gohrnamespace dokuwiki\Parsing\ParserMode;
4*3e6baeffSAndreas Gohr
5*3e6baeffSAndreas Gohruse dokuwiki\Parsing\Handler;
6*3e6baeffSAndreas Gohr
7*3e6baeffSAndreas Gohr/**
8*3e6baeffSAndreas Gohr * Horizontal rule — single mode covering both DokuWiki and GFM dialects.
9*3e6baeffSAndreas Gohr *
10*3e6baeffSAndreas Gohr * Replaces the legacy DW Hr mode and is always loaded across all four
11*3e6baeffSAndreas Gohr * `$conf['syntax']` settings; the opener pattern self-narrows based on
12*3e6baeffSAndreas Gohr * syntax preference. Pure `dokuwiki` keeps its historical 4-or-more
13*3e6baeffSAndreas Gohr * dashes rule. The other three settings accept 3-or-more of any one
14*3e6baeffSAndreas Gohr * GFM thematic-break character (`-`, `*`, `_`).
15*3e6baeffSAndreas Gohr *
16*3e6baeffSAndreas Gohr * No leading, trailing, or internal whitespace in either flavor: the
17*3e6baeffSAndreas Gohr * delimiter run must be a bare line. The DW pattern's old `[ \t]*`
18*3e6baeffSAndreas Gohr * leading-whitespace tolerance was inert in practice for everything
19*3e6baeffSAndreas Gohr * but 0-1 spaces (Preformatted at sort 20 intercepts ≥ 2 spaces or any
20*3e6baeffSAndreas Gohr * tab); dropping it costs nothing real and keeps both flavors strict.
21*3e6baeffSAndreas Gohr *
22*3e6baeffSAndreas Gohr * Emits the existing `hr` handler call so renderers, downloads and
23*3e6baeffSAndreas Gohr * call shape are unchanged.
24*3e6baeffSAndreas Gohr */
25*3e6baeffSAndreas Gohrclass GfmHr extends AbstractMode
26*3e6baeffSAndreas Gohr{
27*3e6baeffSAndreas Gohr    /** @inheritdoc */
28*3e6baeffSAndreas Gohr    public function getSort()
29*3e6baeffSAndreas Gohr    {
30*3e6baeffSAndreas Gohr        return 160;
31*3e6baeffSAndreas Gohr    }
32*3e6baeffSAndreas Gohr
33*3e6baeffSAndreas Gohr    /** @inheritdoc */
34*3e6baeffSAndreas Gohr    public function connectTo($mode)
35*3e6baeffSAndreas Gohr    {
36*3e6baeffSAndreas Gohr        global $conf;
37*3e6baeffSAndreas Gohr
38*3e6baeffSAndreas Gohr        $pattern = $conf['syntax'] === 'dokuwiki'
39*3e6baeffSAndreas Gohr            ? '\n-{4,}(?=\n)'
40*3e6baeffSAndreas Gohr            : '\n(?:-{3,}|\*{3,}|_{3,})(?=\n)';
41*3e6baeffSAndreas Gohr
42*3e6baeffSAndreas Gohr        $this->Lexer->addSpecialPattern($pattern, $mode, 'gfm_hr');
43*3e6baeffSAndreas Gohr    }
44*3e6baeffSAndreas Gohr
45*3e6baeffSAndreas Gohr    /** @inheritdoc */
46*3e6baeffSAndreas Gohr    public function handle($match, $state, $pos, Handler $handler)
47*3e6baeffSAndreas Gohr    {
48*3e6baeffSAndreas Gohr        $handler->addCall('hr', [], $pos);
49*3e6baeffSAndreas Gohr        return true;
50*3e6baeffSAndreas Gohr    }
51*3e6baeffSAndreas Gohr}
52