]> git.immae.eu Git - github/wallabag/wallabag.git/blame - inc/3rdparty/htmlpurifier/HTMLPurifier/ChildDef/List.php
remove autoload section in composer.json
[github/wallabag/wallabag.git] / inc / 3rdparty / htmlpurifier / HTMLPurifier / ChildDef / List.php
CommitLineData
d4949327
NL
1<?php\r
2\r
3/**\r
4 * Definition for list containers ul and ol.\r
5 *\r
6 * What does this do? The big thing is to handle ol/ul at the top\r
7 * level of list nodes, which should be handled specially by /folding/\r
8 * them into the previous list node. We generally shouldn't ever\r
9 * see other disallowed elements, because the autoclose behavior\r
10 * in MakeWellFormed handles it.\r
11 */\r
12class HTMLPurifier_ChildDef_List extends HTMLPurifier_ChildDef\r
13{\r
14 /**\r
15 * @type string\r
16 */\r
17 public $type = 'list';\r
18 /**\r
19 * @type array\r
20 */\r
21 // lying a little bit, so that we can handle ul and ol ourselves\r
22 // XXX: This whole business with 'wrap' is all a bit unsatisfactory\r
23 public $elements = array('li' => true, 'ul' => true, 'ol' => true);\r
24\r
25 /**\r
26 * @param array $children\r
27 * @param HTMLPurifier_Config $config\r
28 * @param HTMLPurifier_Context $context\r
29 * @return array\r
30 */\r
31 public function validateChildren($children, $config, $context)\r
32 {\r
33 // Flag for subclasses\r
34 $this->whitespace = false;\r
35\r
36 // if there are no tokens, delete parent node\r
37 if (empty($children)) {\r
38 return false;\r
39 }\r
40\r
41 // the new set of children\r
42 $result = array();\r
43\r
44 // a little sanity check to make sure it's not ALL whitespace\r
45 $all_whitespace = true;\r
46\r
47 $current_li = false;\r
48\r
49 foreach ($children as $node) {\r
50 if (!empty($node->is_whitespace)) {\r
51 $result[] = $node;\r
52 continue;\r
53 }\r
54 $all_whitespace = false; // phew, we're not talking about whitespace\r
55\r
56 if ($node->name === 'li') {\r
57 // good\r
58 $current_li = $node;\r
59 $result[] = $node;\r
60 } else {\r
61 // we want to tuck this into the previous li\r
62 // Invariant: we expect the node to be ol/ul\r
63 // ToDo: Make this more robust in the case of not ol/ul\r
64 // by distinguishing between existing li and li created\r
65 // to handle non-list elements; non-list elements should\r
66 // not be appended to an existing li; only li created\r
67 // for non-list. This distinction is not currently made.\r
68 if ($current_li === false) {\r
69 $current_li = new HTMLPurifier_Node_Element('li');\r
70 $result[] = $current_li;\r
71 }\r
72 $current_li->children[] = $node;\r
73 $current_li->empty = false; // XXX fascinating! Check for this error elsewhere ToDo\r
74 }\r
75 }\r
76 if (empty($result)) {\r
77 return false;\r
78 }\r
79 if ($all_whitespace) {\r
80 return false;\r
81 }\r
82 return $result;\r
83 }\r
84}\r
85\r
86// vim: et sw=4 sts=4\r