Merge pull request #3627 from Icinga/fix/doc-files-must-not-end-with-line-feed

Doc: Respect last line if it does not end with a line feed too
This commit is contained in:
Eric Lippmann 2018-11-19 17:24:24 +01:00 committed by GitHub
commit 7e749d8c53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -158,19 +158,19 @@ class DocParser
$tree = new SimpleTree(); $tree = new SimpleTree();
foreach (new RecursiveIteratorIterator($this->docIterator) as $filename) { foreach (new RecursiveIteratorIterator($this->docIterator) as $filename) {
$file = new SplFileObject($filename); $file = new SplFileObject($filename);
$lastLine = null; $file->setFlags(SplFileObject::READ_AHEAD);
$stack = new SplStack(); $stack = new SplStack();
$cachingIterator = new CachingIterator($file, CachingIterator::TOSTRING_USE_CURRENT); $cachingIterator = new CachingIterator($file);
$insideFencedCodeBlock = false; $insideFencedCodeBlock = false;
for ($cachingIterator->rewind(); $line = $cachingIterator->valid(); $cachingIterator->next()) { for ($cachingIterator->rewind(); $cachingIterator->valid(); $cachingIterator->next()) {
$fileIterator = $cachingIterator->getInnerIterator();
$line = $cachingIterator->current(); $line = $cachingIterator->current();
$header = null; $header = null;
if (substr($line, 0, 3) === '```') { if (substr($line, 0, 3) === '```') {
$insideFencedCodeBlock = ! $insideFencedCodeBlock; $insideFencedCodeBlock = ! $insideFencedCodeBlock;
} elseif (! $insideFencedCodeBlock) { } elseif (! $insideFencedCodeBlock) {
$fileIterator = $cachingIterator->getInnerIterator();
$header = $this->extractHeader($line, $fileIterator->valid() ? $fileIterator->current() : null); $header = $this->extractHeader($line, $fileIterator->valid() ? $fileIterator->current() : null);
} }