1<?php
2
3declare(strict_types=1);
4
5/*
6 * This file is part of the league/commonmark package.
7 *
8 * (c) Colin O'Dell <colinodell@gmail.com>
9 *
10 * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
11 *  - (c) John MacFarlane
12 *
13 * Additional emphasis processing code based on commonmark-java (https://github.com/atlassian/commonmark-java)
14 *  - (c) Atlassian Pty Ltd
15 *
16 * For the full copyright and license information, please view the LICENSE
17 * file that was distributed with this source code.
18 */
19
20namespace League\CommonMark\Delimiter\Processor;
21
22use League\CommonMark\Delimiter\DelimiterInterface;
23use League\CommonMark\Node\Inline\AbstractStringContainer;
24
25/**
26 * Interface for a delimiter processor
27 */
28interface DelimiterProcessorInterface
29{
30    /**
31     * Returns the character that marks the beginning of a delimited node.
32     *
33     * This must not clash with any other processors being added to the environment.
34     */
35    public function getOpeningCharacter(): string;
36
37    /**
38     * Returns the character that marks the ending of a delimited node.
39     *
40     * This must not clash with any other processors being added to the environment.
41     *
42     * Note that for a symmetric delimiter such as "*", this is the same as the opening.
43     */
44    public function getClosingCharacter(): string;
45
46    /**
47     * Minimum number of delimiter characters that are needed to active this.
48     *
49     * Must be at least 1.
50     */
51    public function getMinLength(): int;
52
53    /**
54     * Determine how many (if any) of the delimiter characters should be used.
55     *
56     * This allows implementations to decide how many characters to be used
57     * based on the properties of the delimiter runs. An implementation can also
58     * return 0 when it doesn't want to allow this particular combination of
59     * delimiter runs.
60     *
61     * @param DelimiterInterface $opener The opening delimiter run
62     * @param DelimiterInterface $closer The closing delimiter run
63     */
64    public function getDelimiterUse(DelimiterInterface $opener, DelimiterInterface $closer): int;
65
66    /**
67     * Process the matched delimiters, e.g. by wrapping the nodes between opener
68     * and closer in a new node, or appending a new node after the opener.
69     *
70     * Note that removal of the delimiter from the delimiter nodes and detaching
71     * them is done by the caller.
72     *
73     * @param AbstractStringContainer $opener       The node that contained the opening delimiter
74     * @param AbstractStringContainer $closer       The node that contained the closing delimiter
75     * @param int                     $delimiterUse The number of delimiters that were used
76     */
77    public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse): void;
78}
79