xref: /dokuwiki/inc/Parsing/ParserMode/GfmBacktickDouble.php (revision 1c00c02121477c81b95fe750b94acdf109cba20a)
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     * Delimiter: exactly two backticks, guarded against longer runs.
34     */
35    protected function getDelimiterPattern(): string
36    {
37        return '(?<!`)``(?!`)';
38    }
39
40    /**
41     * Span body. Admits a lone backtick (one that isn't followed by
42     * another, so not part of a run-of-two) instead of the parent's
43     * backtick runs — such a stray backtick cannot form a valid n=2
44     * closer. Deterministic and possessive like the parent's body.
45     */
46    protected function getBodyPattern(): string
47    {
48        return '(?:[^`\n]++|' . self::NOT_AT_PARA_BREAK . '\n|`(?!`))++';
49    }
50}
51