xref: /dokuwiki/inc/Parsing/ParserMode/GfmBacktickDouble.php (revision 8ed75a23932353c18b43f67323808e9a662f532a)
1<?php
2
3namespace dokuwiki\Parsing\ParserMode;
4
5/**
6 * GFM inline code span bounded by double backticks: ``text``.
7 *
8 * The whole point of the double form is to let users embed literal
9 * backticks in inline code. The input ``foo`bar`` renders as
10 * <code>foo`bar</code> because a lone backtick in the body cannot
11 * form a valid two-backtick closer. Combined with the edge-space
12 * strip rule, you can embed backticks right at the boundaries: the
13 * input `` `foo` `` renders as <code>`foo`</code>.
14 *
15 * Extends GfmBacktickSingle to inherit handle() and normalizeBody;
16 * only the delimiter length and the body character class differ.
17 * Sort and category match the parent so the two modes share one
18 * precedence slot — the (?<!`)...(?!`) guards on both mean the n=1
19 * and n=2 patterns never steal each other's input regardless of
20 * registration order.
21 *
22 * @see GfmBacktickSingle
23 */
24class GfmBacktickDouble extends GfmBacktickSingle
25{
26    /** @inheritdoc */
27    protected function getModeName(): string
28    {
29        return 'gfm_backtick_double';
30    }
31
32    /**
33     * Entry pattern. Same shape as the parent but with doubled
34     * delimiters. The body character class admits either a non-backtick
35     * or a lone backtick (one that isn't followed by another, so not
36     * part of a run-of-two) — such a stray backtick cannot form a valid
37     * n=2 closer.
38     */
39    protected function getEntryPattern(): string
40    {
41        return '(?<!`)``(?!`)(?='
42            . '(?:' . self::NOT_AT_PARA_BREAK . '(?:[^`]|`(?!`)))+'
43            . '(?<!`)``(?!`)'
44            . ')';
45    }
46
47    /** @inheritdoc */
48    protected function getExitPattern(): string
49    {
50        return '(?<!`)``(?!`)';
51    }
52}
53