1*bcefb8aeSAndreas Gohr<?php 2*bcefb8aeSAndreas Gohr 3*bcefb8aeSAndreas Gohrnamespace dokuwiki\Parsing\ParserMode; 4*bcefb8aeSAndreas Gohr 5*bcefb8aeSAndreas Gohr/** 6*bcefb8aeSAndreas Gohr * GFM / CommonMark emphasis via single underscores: `_text_`. 7*bcefb8aeSAndreas Gohr * 8*bcefb8aeSAndreas Gohr * Only loaded when Markdown is the only or preferred syntax 9*bcefb8aeSAndreas Gohr * 10*bcefb8aeSAndreas Gohr * Emits emphasis_open / emphasis_close — the same instructions as DokuWiki's 11*bcefb8aeSAndreas Gohr * Emphasis (`//`) and GfmEmphasis (`*`), so all three render as <em>. 12*bcefb8aeSAndreas Gohr */ 13*bcefb8aeSAndreas Gohrclass GfmEmphasisUnderscore extends AbstractFormatting 14*bcefb8aeSAndreas Gohr{ 15*bcefb8aeSAndreas Gohr /** @inheritdoc */ 16*bcefb8aeSAndreas Gohr public function getSort() 17*bcefb8aeSAndreas Gohr { 18*bcefb8aeSAndreas Gohr return 80; 19*bcefb8aeSAndreas Gohr } 20*bcefb8aeSAndreas Gohr 21*bcefb8aeSAndreas Gohr /** @inheritdoc */ 22*bcefb8aeSAndreas Gohr protected function getModeName(): string 23*bcefb8aeSAndreas Gohr { 24*bcefb8aeSAndreas Gohr return 'gfm_emphasis_underscore'; 25*bcefb8aeSAndreas Gohr } 26*bcefb8aeSAndreas Gohr 27*bcefb8aeSAndreas Gohr /** @inheritdoc */ 28*bcefb8aeSAndreas Gohr protected function getInstructionName(): string 29*bcefb8aeSAndreas Gohr { 30*bcefb8aeSAndreas Gohr return 'emphasis'; 31*bcefb8aeSAndreas Gohr } 32*bcefb8aeSAndreas Gohr 33*bcefb8aeSAndreas Gohr /** @inheritdoc */ 34*bcefb8aeSAndreas Gohr protected function getEntryPattern(): string 35*bcefb8aeSAndreas Gohr { 36*bcefb8aeSAndreas Gohr // Entry requires a valid closing `_` (non-whitespace char before it AND 37*bcefb8aeSAndreas Gohr // NO_WORD_AFTER following). Otherwise emphasis would open with no way 38*bcefb8aeSAndreas Gohr // to ever close (or close at an invalid position). 39*bcefb8aeSAndreas Gohr return self::NO_WORD_BEFORE 40*bcefb8aeSAndreas Gohr . '_(?=[^\s_])' 41*bcefb8aeSAndreas Gohr . '(?=' . self::CONTENT_UNTIL_PARA . '[^\s]_' . self::NO_WORD_AFTER . ')'; 42*bcefb8aeSAndreas Gohr } 43*bcefb8aeSAndreas Gohr 44*bcefb8aeSAndreas Gohr /** @inheritdoc */ 45*bcefb8aeSAndreas Gohr protected function getExitPattern(): string 46*bcefb8aeSAndreas Gohr { 47*bcefb8aeSAndreas Gohr return '(?<=[^\s])_' . self::NO_WORD_AFTER; 48*bcefb8aeSAndreas Gohr } 49*bcefb8aeSAndreas Gohr} 50