ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
HTMLPurifier_Arborize Class Reference

Converts a stream of HTMLPurifier_Token into an HTMLPurifier_Node, and back again. More...

+ Collaboration diagram for HTMLPurifier_Arborize:

Static Public Member Functions

static arborize ($tokens, $config, $context)
 
static flatten ($node, $config, $context)
 

Detailed Description

Converts a stream of HTMLPurifier_Token into an HTMLPurifier_Node, and back again.

Note
This transformation is not an equivalence. We mutate the input token stream to make it so; see all [MUT] markers in code.

Definition at line 10 of file Arborize.php.

Member Function Documentation

◆ arborize()

static HTMLPurifier_Arborize::arborize (   $tokens,
  $config,
  $context 
)
static

Definition at line 12 of file Arborize.php.

References $r.

Referenced by HTMLPurifier_Strategy_FixNesting\execute().

12  {
13  $definition = $config->getHTMLDefinition();
14  $parent = new HTMLPurifier_Token_Start($definition->info_parent);
15  $stack = array($parent->toNode());
16  foreach ($tokens as $token) {
17  $token->skip = null; // [MUT]
18  $token->carryover = null; // [MUT]
19  if ($token instanceof HTMLPurifier_Token_End) {
20  $token->start = null; // [MUT]
21  $r = array_pop($stack);
22  assert($r->name === $token->name);
23  assert(empty($token->attr));
24  $r->endCol = $token->col;
25  $r->endLine = $token->line;
26  $r->endArmor = $token->armor;
27  continue;
28  }
29  $node = $token->toNode();
30  $stack[count($stack)-1]->children[] = $node;
31  if ($token instanceof HTMLPurifier_Token_Start) {
32  $stack[] = $node;
33  }
34  }
35  assert(count($stack) == 1);
36  return $stack[0];
37  }
Concrete end token class.
Definition: End.php:10
Concrete start token class.
Definition: Start.php:6
$r
+ Here is the caller graph for this function:

◆ flatten()

static HTMLPurifier_Arborize::flatten (   $node,
  $config,
  $context 
)
static

Definition at line 39 of file Arborize.php.

Referenced by HTMLPurifier_Strategy_FixNesting\execute().

39  {
40  $level = 0;
41  $nodes = array($level => new HTMLPurifier_Queue(array($node)));
42  $closingTokens = array();
43  $tokens = array();
44  do {
45  while (!$nodes[$level]->isEmpty()) {
46  $node = $nodes[$level]->shift(); // FIFO
47  list($start, $end) = $node->toTokenPair();
48  if ($level > 0) {
49  $tokens[] = $start;
50  }
51  if ($end !== NULL) {
52  $closingTokens[$level][] = $end;
53  }
54  if ($node instanceof HTMLPurifier_Node_Element) {
55  $level++;
56  $nodes[$level] = new HTMLPurifier_Queue();
57  foreach ($node->children as $childNode) {
58  $nodes[$level]->push($childNode);
59  }
60  }
61  }
62  $level--;
63  if ($level && isset($closingTokens[$level])) {
64  while ($token = array_pop($closingTokens[$level])) {
65  $tokens[] = $token;
66  }
67  }
68  } while ($level > 0);
69  return $tokens;
70  }
Concrete element node class.
Definition: Element.php:6
A simple array-backed queue, based off of the classic Okasaki persistent amortized queue...
Definition: Queue.php:20
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: