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