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