xref: /dokuwiki/inc/Parsing/ParserMode/GfmDeleted.php (revision 75364f13219a5af44f52c564ea0a62df64c3a17f)
1<?php
2
3namespace dokuwiki\Parsing\ParserMode;
4
5/**
6 * GFM strikethrough via paired double tildes: `~~text~~`.
7 *
8 * Emits deleted_open / deleted_close — the same instructions as DokuWiki's
9 * Deleted (`<del>…</del>`), so both syntaxes render as <del>.
10 */
11class GfmDeleted extends AbstractFormatting
12{
13    /** @inheritdoc */
14    public function getSort()
15    {
16        return 130;
17    }
18
19    /** @inheritdoc */
20    protected function getModeName(): string
21    {
22        return 'gfm_deleted';
23    }
24
25    /** @inheritdoc */
26    protected function getInstructionName(): string
27    {
28        return 'deleted';
29    }
30
31    /** @inheritdoc */
32    protected function getEntryPattern(): string
33    {
34        // Broken down:
35        //   (?<!~)                 — not preceded by `~` (runs of 3+ tildes
36        //                            are fenced-code markers, not strike)
37        //   ~~                     — two opening tildes
38        //   (?=[^\s~])             — next body char: not whitespace, not `~`
39        //   (?=                    — lookahead: a valid closer must exist
40        //     CONTENT_UNTIL_PARA   —   body that doesn't cross a blank line
41        //     [^\s]~~              —   non-whitespace, then closing `~~`
42        //     (?!~)                —   and not followed by another `~`
43        //   )
44        return '(?<!~)~~(?=[^\s~])'
45            . '(?=' . self::CONTENT_UNTIL_PARA . '[^\s]~~(?!~))';
46    }
47
48    /** @inheritdoc */
49    protected function getExitPattern(): string
50    {
51        return '(?<=[^\s])~~(?!~)';
52    }
53}
54