Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ListFrame
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 3
72
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 popTags
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
20
 pushList
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2declare( strict_types = 1 );
3
4namespace Wikimedia\Parsoid\Wt2Html\TT;
5
6use Wikimedia\Parsoid\NodeData\DataParsoid;
7use Wikimedia\Parsoid\Tokens\EndTagTk;
8use Wikimedia\Parsoid\Tokens\ListTk;
9use Wikimedia\Parsoid\Tokens\NlTk;
10use Wikimedia\Parsoid\Tokens\TagTk;
11
12/**
13 * Private helper class for ListHandler.
14 *
15 * NOTE: This is *not* a per-list frame.
16 *
17 * This is a frame for every nested context within which list
18 * processing proceeds independent of any parent context.
19 * Currently, *only* tables introduce a new nested parsing context
20 * and lists embedded in a table cell are independent of any list
21 * that the table itself might be embedded in.
22 *
23 * So, if you ignore tables, there will only be a single list frame ever
24 * in the list-frame stack maintained in ListHandler.
25 *
26 * @internal
27 */
28class ListFrame {
29    /**
30     * Flag indicating a list-less line that terminates a list block
31     */
32    public bool $atEOL = true;
33    /**
34     * NlTk that triggered atEOL
35     */
36    public ?NlTk $nlTk = null;
37    public array $solTokens = [];
38    /**
39     * Bullet stack, previous element's listStyle
40     */
41    public array $bstack = [];
42    /**
43     * Stack of end tags
44     * @var list<EndTagTk>
45     */
46    public array $endtags = [];
47    /**
48     * Partial DOM building heuristic:
49     * Number of open block tags encountered within list context.
50     */
51    public int $numOpenBlockTags = 0;
52    /**
53     * Number of open tags encountered within list context.
54     */
55    public int $numOpenTags = 0;
56
57    /**
58     * Did we generate a <dd> already on this line?
59     * Used to convert extra : listitems to ":" instead of extra <dl>s.
60     * Gets reset on encountering a NlTk or a ; listitem.
61     */
62    public bool $haveDD = false;
63
64    public ListTk $listTk;
65
66    public function __construct() {
67        $this->listTk = new ListTk;
68    }
69
70    /**
71     * Handle popping tags after processing
72     *
73     * @param int $n
74     * @return list<EndTagTk>
75     */
76    public function popTags( int $n ): array {
77        $tokens = [];
78        while ( $n > 0 ) {
79            // push list item..
80            $temp = array_pop( $this->endtags );
81            if ( $temp ) {
82                $tokens[] = $temp;
83            }
84            // and the list end tag
85            $temp = array_pop( $this->endtags );
86            if ( $temp ) {
87                $tokens[] = $temp;
88            }
89            $n--;
90        }
91        return $tokens;
92    }
93
94    /**
95     * Push a list
96     *
97     * @return list{TagTk, TagTk}
98     */
99    public function pushList(
100        array $container, DataParsoid $dp1, DataParsoid $dp2
101    ): array {
102        $this->endtags[] = new EndTagTk( $container['list'] );
103        $this->endtags[] = new EndTagTk( $container['item'] );
104
105        if ( $container['item'] === 'dd' ) {
106            $this->haveDD = true;
107        } elseif ( $container['item'] === 'dt' ) {
108            $this->haveDD = false; // reset
109        }
110
111        $this->listTk->listType ??= $container['list'];
112
113        return [
114            new TagTk( $container['list'], [], $dp1 ),
115            new TagTk( $container['item'], [], $dp2 )
116        ];
117    }
118
119}