Merge pull request #3207 from Icinga/bugfix/markdown-doesn-t-ignore-comments-3200

Don't interpret shell comments inside fenced code blocks as MD headers
This commit is contained in:
lippserd 2017-12-14 14:46:41 +01:00 committed by GitHub
commit fcd851d1e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -161,10 +161,19 @@ class DocParser
$lastLine = null;
$stack = new SplStack();
$cachingIterator = new CachingIterator($file, CachingIterator::TOSTRING_USE_CURRENT);
$insideFencedCodeBlock = false;
for ($cachingIterator->rewind(); $line = $cachingIterator->valid(); $cachingIterator->next()) {
$fileIterator = $cachingIterator->getInnerIterator();
$line = $cachingIterator->current();
$header = $this->extractHeader($line, $fileIterator->valid() ? $fileIterator->current() : null);
$header = null;
if (substr($line, 0, 3) === '```') {
$insideFencedCodeBlock = ! $insideFencedCodeBlock;
} elseif (! $insideFencedCodeBlock) {
$header = $this->extractHeader($line, $fileIterator->valid() ? $fileIterator->current() : null);
}
if ($header !== null) {
list($title, $id, $level, $headerStyle) = $header;
while (! $stack->isEmpty() && $stack->top()->getLevel() >= $level) {