forked from Gregwar/RST
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubDirective.php
55 lines (47 loc) · 1.3 KB
/
SubDirective.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace Gregwar\RST;
use Gregwar\RST\Nodes\CodeNode;
/**
* A directive that parses the sub block and call the processSub that can
* be overloaded, like :
*
* .. sub-directive::
* Some block of code
*
* You can imagine anything here, like adding *emphasis*, lists or
* titles
*/
abstract class SubDirective extends Directive
{
/**
* Process a directive that should parces the next node as a "sub" document
*/
public final function process(Parser $parser, $node, $variable, $data, array $options)
{
$subParser = $parser->getSubParser();
if ($node instanceof CodeNode) {
$document = $subParser->parseLocal($node->getValue());
} else {
$document = $node;
}
$newNode = $this->processSub($parser, $document, $variable, $data, $options);
if ($newNode) {
if ($variable) {
$parser->getEnvironment()->setVariable($variable, $newNode);
} else {
$parser->getDocument()->addNode($newNode);
}
}
}
/**
* Process a sub directive
*/
public function processSub(Parser $parser, $document, $variable, $data, array $options)
{
return null;
}
public function wantCode()
{
return true;
}
}