1<?php 2 3namespace dokuwiki\Parsing\ParserMode; 4 5/** 6 * GFM / CommonMark emphasis via single asterisks: `*text*`. 7 * 8 * Emits emphasis_open / emphasis_close — the same instructions as DokuWiki's 9 * Emphasis (`//`), so both syntaxes render as <em>. 10 */ 11class GfmEmphasis extends AbstractFormatting 12{ 13 /** @inheritdoc */ 14 public function getSort() 15 { 16 return 80; 17 } 18 19 /** @inheritdoc */ 20 protected function getModeName(): string 21 { 22 return 'gfm_emphasis'; 23 } 24 25 /** @inheritdoc */ 26 protected function getInstructionName(): string 27 { 28 return 'emphasis'; 29 } 30 31 /** @inheritdoc */ 32 protected function getEntryPattern(): string 33 { 34 // Broken down: 35 // \* — opening `*` 36 // (?= — lookahead: a valid closer must exist 37 // [^\s*] — first body char: not whitespace, not `*` 38 // (flanking-opener rule) 39 // (?: — optional: more body 40 // (?:NOT_AT_PARA_BREAK — …any non-`*` char that doesn't 41 // [^*])* — start a paragraph break 42 // [^\s*] — last body char: not whitespace, not `*` 43 // (flanking-closer rule) 44 // )? — `?` so single-char bodies like `*a*` 45 // also match 46 // \* — closing `*` 47 // ) 48 return '\*(?=[^\s*](?:(?:' . self::NOT_AT_PARA_BREAK . '[^*])*[^\s*])?\*)'; 49 } 50 51 /** @inheritdoc */ 52 protected function getExitPattern(): string 53 { 54 return '(?<=[^\s])\*'; 55 } 56} 57