Skip to content

Commit 1543845

Browse files
committed
update parser version which basically fixes all problems
1 parent 0b04b43 commit 1543845

File tree

5 files changed

+25
-24
lines changed

5 files changed

+25
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/_build/doctrees
22
/_build/html
3+
/_build/json
34
*.pyc

_build/composer.lock

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

_build/notes.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,3 @@ Notes
2323
- we're assuming there is only one toctree per page...
2424
- `rst` does not exist in highlight php
2525
- `varnish` = C ? (highlight php)
26-
27-
Bugs in RST Parser
28-
==================
29-
30-
- problem using glob: listed files are added twice (https://github.com/doctrine/rst-parser/issues/18)
31-
- problem with absolute path in toc trees (https://github.com/doctrine/rst-parser/pull/23)
32-
- problem with `:ref:`, `:doc:` and `*.rst.inc` which are loaded in parseQueue (problem evoked in https://github.com/doctrine/rst-parser/pull/23)
33-
- problem with `.. include::` which are SOMETIMES failing to load (dirty fix in `UrlGenerator::relativeUrl`)

_build/parse.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
use Symfony\Component\Filesystem\Filesystem;
77
use Symfony\Component\Finder\Finder;
88
use SymfonyDocs\HtmlKernel;
9+
use SymfonyDocs\JsonGenerator;
910

1011
$kernel = new HtmlKernel();
1112
$builder = new Builder($kernel);
1213

1314
$fs = new Filesystem();
14-
$fs->remove(__DIR__.'/html');
15+
$fs->remove($htmlOutputDir = __DIR__.'/html');
16+
$fs->remove($jsonOutputDir = __DIR__.'/json');
1517

1618
$builder->build(
1719
__DIR__.'/..',
18-
__DIR__.'/html',
19-
true
20+
$htmlOutputDir
2021
);
2122

2223
$finder = new Finder();
@@ -32,4 +33,7 @@
3233
}
3334
}
3435

36+
$jsonGenerator = new JsonGenerator($builder->getDocuments()->getAll());
37+
$jsonGenerator->generateJson($htmlOutputDir, $jsonOutputDir);
38+
3539

_build/src/JsonGenerator.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private function getParserFilename(string $filePath, string $inputDir): string
7171
private function getEnvironment(string $parserFilename): Environment
7272
{
7373
if (!isset($this->environments[$parserFilename])) {
74-
throw new \LogicException(sprintf('Cannot guess file name in parser "%s"', $parserFilename));
74+
throw new \LogicException(sprintf('Cannot find environment for file "%s"', $parserFilename));
7575
}
7676

7777
return $this->environments[$parserFilename];
@@ -117,9 +117,11 @@ private function guessNext(string $parserFilename): ?array
117117
return null;
118118
}
119119

120+
$nextFileName = $toc[$indexCurrentFile + 1];
121+
120122
return [
121-
'title' => $this->getMeta($toc[$indexCurrentFile + 1])->getTitle(),
122-
'link' => $this->getMeta($toc[$indexCurrentFile + 1])->getUrl(),
123+
'title' => $this->getMeta($nextFileName)->getTitle(),
124+
'link' => $this->getMeta($nextFileName)->getUrl(),
123125
];
124126
}
125127

@@ -131,9 +133,11 @@ private function guessPrev(string $parserFilename): ?array
131133
return null;
132134
}
133135

136+
$prevFileName = $toc[$indexCurrentFile - 1];
137+
134138
return [
135-
'title' => $this->getMeta($toc[$indexCurrentFile - 1])->getTitle(),
136-
'link' => $this->getMeta($toc[$indexCurrentFile - 1])->getUrl(),
139+
'title' => $this->getMeta($prevFileName)->getTitle(),
140+
'link' => $this->getMeta($prevFileName)->getUrl(),
137141
];
138142
}
139143

@@ -143,19 +147,19 @@ private function getNextPrevInformation(string $parserFilename): ?array
143147
$parentFile = $meta->getParent();
144148

145149
if (!$parentFile) {
146-
return [null, null];
150+
return [null, null, null];
147151
}
148152

149153
$metaParent = $this->getMeta($parentFile);
150154

151155
if (!$metaParent->getTocs() || \count($metaParent->getTocs()) !== 1) {
152-
return [null, null];
156+
return [null, null, null];
153157
}
154158

155159
$toc = current($metaParent->getTocs());
156160

157161
if (\count($toc) < 2 || !isset(array_flip($toc)[$parserFilename])) {
158-
return [null, null];
162+
return [null, null, null];
159163
}
160164

161165
$indexCurrentFile = array_flip($toc)[$parserFilename];

0 commit comments

Comments
 (0)