xref: /dokuwiki/inc/Parsing/ParserMode/GfmEmphasisStrongUnderscore.php (revision 2bb62bca317961d66fa2908b40f183af01402a91)
1<?php
2
3namespace dokuwiki\Parsing\ParserMode;
4
5/**
6 * GFM / CommonMark em-wrapping-strong via triple underscores: `___text___`.
7 *
8 * Only loaded when Markdown is the only or preferred syntax. Renders as
9 * <em><strong>text</strong></em>. Only the exact 3+3 symmetric variant is
10 * supported; longer and asymmetric runs require CommonMark's full
11 * delimiter-pairing algorithm and are out of scope.
12 *
13 * Inherits `handle()` and `getSort()` from GfmEmphasisStrong since the
14 * emitted instructions and sort priority are identical; only the delimiter
15 * patterns and word-boundary rules differ.
16 */
17class GfmEmphasisStrongUnderscore extends GfmEmphasisStrong
18{
19    /** @inheritdoc */
20    protected function getModeName(): string
21    {
22        return 'gfm_emphasis_strong_underscore';
23    }
24
25    /** @inheritdoc */
26    protected function getEntryPattern(): string
27    {
28        // NO_WORD_BEFORE + `(?<!_)` blocks intraword and longer-run openers.
29        // `(?=[^\s_])` enforces the flanking-opener rule.
30        // The closing-delimiter lookahead requires non-whitespace before `___`,
31        // `(?!_)` for exactly-3 length, and NO_WORD_AFTER for word-boundary.
32        return self::NO_WORD_BEFORE
33            . '(?<!_)___(?=[^\s_])'
34            . '(?=' . self::CONTENT_UNTIL_PARA . '[^\s]___(?!_)' . self::NO_WORD_AFTER . ')';
35    }
36
37    /** @inheritdoc */
38    protected function getExitPattern(): string
39    {
40        return '(?<=[^\s])___(?!_)' . self::NO_WORD_AFTER;
41    }
42}
43