Skip to content

Commit f522f00

Browse files
committed
making the main test pass
1 parent 84b235e commit f522f00

34 files changed

+712
-822
lines changed

_build/composer.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_build/notes.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@ Changes needed in symfony.com
44
- For `caution`, `note` and `tip` : remove `class="last"` in favor to `:last-child`
55
- idem about `.first`
66
- idem for `sidebar` (the `.first` css class is not even used in css)
7-
7+
- `div.section` are now removed, so the `margin-top` needd to go on `<hX>`
8+
- `<p>` added to `.. seealso::` directive
89

910
Notes
1011
=====
1112

1213
- add some format check on references
1314
- toc tree bugs whith :glob: (issue opened)
15+
- should we print breadcrumb ?
16+
- error in main : toctree
17+
- `<ul>` in table = `<ul class="first last simple">` why ?
18+
- /!\ tip / caution / node / etc... with nested reference
19+
- no more `colgroup` in tables ??
20+
- add `&nbsp` instead of simple space to lines in code blocks

_build/src/Directive/SeeAlsoDirective.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
namespace SymfonyDocs\Directive;
44

55
use Doctrine\RST\Nodes\Node;
6-
use Doctrine\RST\Nodes\RawNode;
76
use Doctrine\RST\Nodes\WrapperNode;
87
use Doctrine\RST\Parser;
98
use Doctrine\RST\SubDirective;
109

1110
class SeeAlsoDirective extends SubDirective
1211
{
13-
public function getName() : string
12+
public function getName(): string
1413
{
1514
return 'seealso';
1615
}
@@ -24,7 +23,7 @@ public function processSub(
2423
string $variable,
2524
string $data,
2625
array $options
27-
) : ?Node {
28-
return new RawNode(sprintf('<div class="admonition-wrapper"><div class="seealso"></div><div class="admonition admonition-seealso">%s</div></div>', trim(strip_tags((string) $document))));
26+
): ?Node {
27+
return new WrapperNode($document, '<div class="admonition-wrapper"><div class="seealso"></div><div class="admonition admonition-seealso">', '</div></div>');
2928
}
3029
}

_build/src/Directive/VersionAddedDirective.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ public function processSub(
2424
string $data,
2525
array $options
2626
): ?Node {
27-
return new RawNode(sprintf('<div class="versionadded"><p><span class="versionmodified">New in version %s: </span>%s</p></div>', $data, trim(strip_tags((string) $document))));
27+
return new RawNode(sprintf('<div class="versionadded"><p><span class="versionmodified">New in version %s: </span>%s</p></div>', $data, trim(strip_tags((string) $document, '<a><code>'))));
2828
}
2929
}

_build/src/HtmlKernel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace SymfonyDocs;
44

5-
use Doctrine\RST\References\Doc;
65
use Doctrine\RST\Directive;
76
use Doctrine\RST\Factory;
87
use Doctrine\RST\HTML\Kernel;
@@ -18,6 +17,7 @@
1817
use SymfonyDocs\Directive\TipDirective;
1918
use SymfonyDocs\Directive\VersionAddedDirective;
2019
use SymfonyDocs\Reference\ClassReference;
20+
use SymfonyDocs\Reference\DocReference;
2121
use SymfonyDocs\Reference\MethodReference;
2222
use SymfonyDocs\Reference\NamespaceReference;
2323
use SymfonyDocs\Reference\PhpClassReference;
@@ -96,7 +96,7 @@ public function getDirectives(): array
9696
public function getReferences(): array
9797
{
9898
return [
99-
new Doc(),
99+
new DocReference(),
100100
new RefReference(),
101101
new ClassReference(),
102102
new MethodReference(),

_build/src/NodeFactory.php

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,58 @@
44

55
use Doctrine\RST\Environment;
66
use Doctrine\RST\Factory;
7+
use Doctrine\RST\Nodes\AnchorNode;
78
use Doctrine\RST\Nodes\CodeNode;
89
use Doctrine\RST\Nodes\ListNode;
9-
use Doctrine\RST\Nodes\TocNode;
1010
use Doctrine\RST\Nodes\Node;
11+
use Doctrine\RST\Nodes\TitleNode;
12+
use Doctrine\RST\Nodes\TableNode;
13+
use Doctrine\RST\Nodes\TocNode;
14+
use Doctrine\RST\Parser;
15+
use Doctrine\RST\Parser\LineChecker;
16+
use Doctrine\RST\Span;
17+
use SymfonyDocs\Nodes\AnchorNode as SymfonyAnchorNode;
1118
use SymfonyDocs\Nodes\CodeNode as SymfonyCodeNode;
1219
use SymfonyDocs\Nodes\ListNode as SymfonyListNode;
20+
use SymfonyDocs\Nodes\TitleNode as SymfonyTitleNode;
1321
use SymfonyDocs\Nodes\TocNode as SymfonyTocNode;
22+
use SymfonyDocs\Nodes\SpanNode as SymfonySpanNode;
23+
use SymfonyDocs\Nodes\TableNode as SymfonyTableNode;
1424

1525
class NodeFactory extends Factory
1626
{
17-
/**
18-
* @param Node|string|null $value
19-
*/
2027
public function createListNode($value = null): ListNode
2128
{
2229
return new SymfonyListNode($value);
2330
}
2431

25-
/**
26-
* @param string[] $lines
27-
*/
2832
public function createCodeNode(array $lines): CodeNode
2933
{
3034
return new SymfonyCodeNode($lines);
3135
}
3236

33-
/**
34-
* @param string[] $files
35-
* @param string[] $options
36-
*/
3737
public function createTocNode(Environment $environment, array $files, array $options): TocNode
3838
{
3939
return new SymfonyTocNode($environment, $files, $options);
4040
}
41+
42+
public function createTitleNode(Node $value, int $level, string $token): TitleNode
43+
{
44+
return new SymfonyTitleNode($value, $level, $token);
45+
}
46+
47+
public function createAnchorNode($value = null): AnchorNode
48+
{
49+
return new SymfonyAnchorNode($value);
50+
}
51+
52+
public function createSpan(Parser $parser, $span): Span
53+
{
54+
return new SymfonySpanNode($parser, $span);
55+
}
56+
57+
public function createTableNode(array $parts, string $type, LineChecker $lineChecker) : TableNode
58+
{
59+
return new SymfonyTableNode($parts, $type, $lineChecker);
60+
}
4161
}

_build/src/Nodes/AnchorNode.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace SymfonyDocs\Nodes;
4+
5+
use Doctrine\RST\Nodes\AnchorNode as Base;
6+
7+
class AnchorNode extends Base
8+
{
9+
public function render(): string
10+
{
11+
return '<span id="'.$this->value.'"></span>';
12+
}
13+
}
14+

_build/src/Nodes/SpanNode.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace SymfonyDocs\Nodes;
4+
5+
use Doctrine\RST\HTML\Span;
6+
7+
class SpanNode extends Span
8+
{
9+
public function link(?string $url, string $title, array $attributes = []): string
10+
{
11+
if (isset($attributes['is-ref'])) {
12+
$title = '<span>'.$title.'</span>';
13+
unset($attributes['is-ref']);
14+
}
15+
if (isset($attributes['is-doc'])) {
16+
$title = '<em>'.$title.'</em>';
17+
unset($attributes['is-doc']);
18+
}
19+
if (!$attributes) {
20+
$attributes['class'] = sprintf('reference %s', 0 === strpos($url, 'http') ? 'external' : 'internal');
21+
}
22+
23+
$htmlAttributes = implode(
24+
' ',
25+
array_map(
26+
static function ($attribute, $value) {
27+
return sprintf('%s="%s"', $attribute, htmlspecialchars((string) $value));
28+
},
29+
array_keys($attributes),
30+
$attributes
31+
)
32+
);
33+
34+
return '<a href="'.htmlspecialchars((string) $url).'"'.($htmlAttributes !== '' ? ' '.$htmlAttributes : '').'>'.$title.'</a>';
35+
}
36+
}

_build/src/Nodes/TableNode.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace SymfonyDocs\Nodes;
4+
5+
use Doctrine\RST\HTML\Span;
6+
use Doctrine\RST\Nodes\TableNode as Base;
7+
8+
class TableNode extends Base
9+
{
10+
public function render(): string
11+
{
12+
$html = '<table class="docutils" border="1">';
13+
14+
$i = 0;
15+
if (0 !== \count($this->headers)) {
16+
$html .= '<thead valign="bottom"><tr class="row-odd">';
17+
18+
foreach ($this->headers as $k => $isHeader) {
19+
if (isset($this->data[$k])) {
20+
/** @var Span $col */
21+
foreach ($this->data[$k] as &$col) {
22+
$html .= sprintf('<th class="head">%s</th>', $col->render());
23+
}
24+
25+
unset($this->data[$k]);
26+
}
27+
}
28+
29+
$html .= '</tr></thead>';
30+
$i++;
31+
}
32+
33+
$html .= '<tbody valign="top">';
34+
35+
foreach ($this->data as $k => &$row) {
36+
if ($row === []) {
37+
continue;
38+
}
39+
40+
$html .= sprintf('<tr class="row-%s">', $i++ % 2 ? 'even' : 'odd');
41+
42+
/** @var Span $col */
43+
foreach ($row as &$col) {
44+
$html .= sprintf('<td>%s</td>', $col->render());
45+
}
46+
47+
$html .= '</tr>';
48+
}
49+
50+
$html .= '</tbody></table>';
51+
52+
return $html;
53+
}
54+
}
55+

_build/src/Nodes/TitleNode.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace SymfonyDocs\Nodes;
4+
5+
use Doctrine\RST\Environment;
6+
use Doctrine\RST\Nodes\TitleNode as Base;
7+
8+
class TitleNode extends Base
9+
{
10+
public function render(): string
11+
{
12+
$anchor = Environment::slugify((string) $this->value);
13+
14+
return '<h'.$this->level.' id="'.$anchor.'">'.$this->value.'<a class="headerlink" href="#'.$anchor.'" title="Permalink to this headline">¶</a></h'.$this->level.'>';
15+
}
16+
}
17+

_build/src/Nodes/TocNode.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class TocNode extends Base
1111
/** @var int */
1212
private $depth;
1313

14-
public function render() : string
14+
public function render(): string
1515
{
1616
if (isset($this->options['hidden'])) {
1717
return '';
@@ -43,8 +43,7 @@ private function renderLevel(
4343
array $titles,
4444
int $level = 1,
4545
array $path = []
46-
) : string {
47-
46+
): string {
4847
if (-1 !== $this->depth && $level > $this->depth) {
4948
return '';
5049
}
@@ -53,25 +52,38 @@ private function renderLevel(
5352
foreach ($titles as $k => $entry) {
5453
$path[$level - 1] = (int) $k + 1;
5554

56-
list($title, $childs) = $entry;
55+
[$title, $children] = $entry;
56+
57+
$slug = $title;
58+
59+
if (is_array($title)) {
60+
$slug = $title[1];
61+
}
62+
63+
$anchor = Environment::slugify($slug);
64+
$target = $url;
65+
if (1 !== $level) {
66+
$target = $url . '#' . $anchor;
67+
}
5768

5869
if (is_array($title)) {
59-
list($title, $target) = $title;
70+
[$title, $target] = $title;
6071

6172
$info = $this->environment->resolve('doc', $target);
6273

63-
$url = $this->environment->relativeUrl($info->getUrl());
74+
$target = $this->environment->relativeUrl($info->getUrl());
6475
}
6576

66-
$html .= sprintf('<li class="toctree-l%s"><a class="reference internal" href="%s">%s</a></li>', $level, $url, $title);
77+
$html .= sprintf('<li class="toctree-l%s"><a class="reference internal" href="%s">%s</a>', $level, $target, $title);
6778

68-
if (! $childs) {
69-
continue;
79+
if ($children && ($level < $this->depth || -1 === $this->depth)) {
80+
$html .= '<ul>';
81+
$html .= $this->renderLevel($url, $children, $level + 1, $path);
82+
$html .= '</ul>';
7083
}
7184

72-
$html .= '<ul>';
73-
$html .= $this->renderLevel($url, $childs, $level + 1, $path);
74-
$html .= '</ul>';
85+
$html .= '</li>';
86+
7587
}
7688

7789
return $html;

_build/src/Reference/ClassReference.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function resolve(Environment $environment, string $data): ResolvedReferen
2121
$className = str_replace('\\\\', '\\', $data);
2222

2323
return new ResolvedReference(
24-
$className,
24+
substr(strrchr($className, '\\'), 1),
2525
sprintf('%s/%s/%s.html', self::BASE__URL, HtmlKernel::getVersion(), str_replace('\\', '/', $className)),
2626
[],
2727
[

0 commit comments

Comments
 (0)