From 9c7cfca9eca4b4025a725b291e22d3f83737c816 Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Mon, 2 Dec 2024 13:17:42 +0400 Subject: [PATCH 01/16] feat(documentator)!: `\LastDragon_ru\LaraASP\Documentator\Processor\Processor::run($path)` can be a `\LastDragon_ru\LaraASP\Core\Path\FilePath`. --- .../Processor/Exceptions/ProcessingFailed.php | 12 +- .../documentator/src/Processor/Processor.php | 30 +- .../src/Processor/ProcessorTest.php | 396 +++++++++--------- 3 files changed, 222 insertions(+), 216 deletions(-) diff --git a/packages/documentator/src/Processor/Exceptions/ProcessingFailed.php b/packages/documentator/src/Processor/Exceptions/ProcessingFailed.php index 75d0c5ad..6c5a3659 100644 --- a/packages/documentator/src/Processor/Exceptions/ProcessingFailed.php +++ b/packages/documentator/src/Processor/Exceptions/ProcessingFailed.php @@ -2,26 +2,26 @@ namespace LastDragon_ru\LaraASP\Documentator\Processor\Exceptions; -use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory; +use LastDragon_ru\LaraASP\Core\Path\Path; use Throwable; use function sprintf; class ProcessingFailed extends ProcessorError { public function __construct( - protected Directory $root, + protected Path $path, ?Throwable $previous = null, ) { parent::__construct( sprintf( - 'Processing failed (root: `%s`)', - $this->root->getPath(), + 'Processing failed (path: `%s`)', + $this->path, ), $previous, ); } - public function getRoot(): Directory { - return $this->root; + public function getPath(): Path { + return $this->path; } } diff --git a/packages/documentator/src/Processor/Processor.php b/packages/documentator/src/Processor/Processor.php index 9bbc211f..8494ecad 100644 --- a/packages/documentator/src/Processor/Processor.php +++ b/packages/documentator/src/Processor/Processor.php @@ -60,24 +60,34 @@ public function task(Task|string $task, ?Closure $configurator = null): static { * @param array|string|null $exclude glob(s) to exclude. * @param Closure(FilePath $path, Result $result, float $duration): void|null $listener */ - public function run(DirectoryPath $path, array|string|null $exclude = null, ?Closure $listener = null): float { - $start = microtime(true); - $extensions = !$this->tasks->has('*') - ? array_map(static fn ($e) => "*.{$e}", $this->tasks->keys()) - : null; - $exclude = array_map(Glob::toRegex(...), (array) $exclude); - $root = new Directory($path, true); - $fs = new FileSystem(); + public function run( + DirectoryPath|FilePath $path, + array|string|null $exclude = null, + ?Closure $listener = null, + ): float { + $start = microtime(true); + $depth = match (true) { + $path instanceof FilePath => 0, + default => null, + }; + $extensions = match (true) { + $path instanceof FilePath => $path->getName(), + !$this->tasks->has('*') => array_map(static fn ($e) => "*.{$e}", $this->tasks->keys()), + default => null, + }; + $exclude = array_map(Glob::toRegex(...), (array) $exclude); + $root = new Directory($path->getDirectoryPath(), true); + $fs = new FileSystem(); try { - $iterator = $fs->getFilesIterator($root, patterns: $extensions, exclude: $exclude); + $iterator = $fs->getFilesIterator($root, $extensions, $depth, $exclude); $executor = new Executor($fs, $root, $exclude, $this->tasks, $iterator, $listener); $executor->run(); } catch (ProcessorError $exception) { throw $exception; } catch (Exception $exception) { - throw new ProcessingFailed($root, $exception); + throw new ProcessingFailed($path, $exception); } return microtime(true) - $start; diff --git a/packages/documentator/src/Processor/ProcessorTest.php b/packages/documentator/src/Processor/ProcessorTest.php index 5eb9bbe5..c0b462ee 100644 --- a/packages/documentator/src/Processor/ProcessorTest.php +++ b/packages/documentator/src/Processor/ProcessorTest.php @@ -33,12 +33,7 @@ public function testRun(): void { ->once() ->andReturns(['php']); - $taskA = new class() implements Task { - /** - * @var array - */ - public array $processed = []; - + $taskA = new class() extends ProcessorTest__Task { /** * @inheritDoc */ @@ -46,74 +41,20 @@ public function testRun(): void { public static function getExtensions(): array { return ['htm']; } - - /** - * @inheritDoc - */ - #[Override] - public function __invoke(Directory $root, File $file): bool { - $this->processed[] = (string) $root->getRelativePath($file); - - return true; - } - }; - $taskB = new class() implements Task { - /** - * @var array}> - */ - public array $processed = []; - - /** - * @inheritDoc - */ - #[Override] - public static function getExtensions(): array { - return ['txt', 'md']; - } - - /** - * @return Generator, mixed, bool> - */ - #[Override] - public function __invoke(Directory $root, File $file): Generator { - $resolved = []; - $dependencies = match ($file->getName()) { - 'a.txt' => [ - '../b/b/bb.txt', - '../c.txt', - '../c.html', - 'excluded.txt', - ], - 'bb.txt' => [ - '../../b/a/ba.txt', - '../../c.txt', - '../../../../../README.md', - ], - default => [ - // empty - ], - }; - - foreach ($dependencies as $dependency) { - $resolved[$dependency] = yield new FileReference($dependency); - } - - $this->processed[] = [ - (string) $root->getRelativePath($file), - array_map( - static function (mixed $file) use ($root): mixed { - return (string) match (true) { - $file instanceof File => $root->getRelativePath($file), - default => null, - }; - }, - $resolved, - ), - ]; - - return true; - } }; + $taskB = new ProcessorTest__Task([ + 'a.txt' => [ + '../b/b/bb.txt', + '../c.txt', + '../c.html', + 'excluded.txt', + ], + 'bb.txt' => [ + '../../b/a/ba.txt', + '../../c.txt', + '../../../../../README.md', + ], + ]); $root = (new DirectoryPath(self::getTestData()->path('')))->getNormalizedPath(); $count = 0; @@ -151,7 +92,10 @@ static function (FilePath $path, Result $result) use (&$count, &$events): void { self::assertCount($count, $events); self::assertEquals( [ - 'c.htm', + [ + 'c.htm', + [], + ], ], $taskA->processed, ); @@ -199,6 +143,49 @@ static function (FilePath $path, Result $result) use (&$count, &$events): void { ); } + public function testRunFile(): void { + $task = new ProcessorTest__Task([ + 'c.txt' => [ + 'excluded.txt', + ], + ]); + + $path = (new FilePath(self::getTestData()->path('c.txt')))->getNormalizedPath(); + $count = 0; + $events = []; + + (new Processor($this->app()->make(ContainerResolver::class))) + ->task($task) + ->run( + $path, + ['excluded.txt', '**/**/excluded.txt'], + static function (FilePath $path, Result $result) use (&$count, &$events): void { + $events[(string) $path] = $result; + $count++; + }, + ); + + self::assertEquals( + [ + 'c.txt' => Result::Success, + 'excluded.txt' => Result::Skipped, + ], + $events, + ); + self::assertCount($count, $events); + self::assertEquals( + [ + [ + 'c.txt', + [ + 'excluded.txt' => 'excluded.txt', + ], + ], + ], + $task->processed, + ); + } + public function testRunPostpone(): void { $task = new class() implements Task { /** @@ -298,12 +285,12 @@ static function (FilePath $path, Result $result) use (&$count, &$events): void { } public function testRunWildcard(): void { - $taskA = new class() implements Task { - /** - * @var array - */ - public array $processed = []; - + $taskA = new class([ + 'b.html' => [ + '../../../../README.md', + '../a/excluded.txt', + ], + ]) extends ProcessorTest__Task { /** * @inheritDoc */ @@ -311,37 +298,8 @@ public function testRunWildcard(): void { public static function getExtensions(): array { return ['html']; } - - /** - * @return Generator, mixed, bool> - */ - #[Override] - public function __invoke(Directory $root, File $file): Generator { - $dependencies = match ($file->getName()) { - 'b.html' => [ - '../../../../README.md', - '../a/excluded.txt', - ], - default => [ - // empty - ], - }; - - foreach ($dependencies as $dependency) { - yield new FileReference($dependency); - } - - $this->processed[] = (string) $root->getRelativePath($file); - - return true; - } }; - $taskB = new class() implements Task { - /** - * @var array - */ - public array $processed = []; - + $taskB = new class() extends ProcessorTest__Task { /** * @inheritDoc */ @@ -349,13 +307,6 @@ public function __invoke(Directory $root, File $file): Generator { public static function getExtensions(): array { return ['*']; } - - #[Override] - public function __invoke(Directory $root, File $file): bool { - $this->processed[] = (string) $root->getRelativePath($file); - - return true; - } }; $root = (new DirectoryPath(self::getTestData()->path('')))->getNormalizedPath(); @@ -395,51 +346,77 @@ static function (FilePath $path, Result $result) use (&$count, &$events): void { self::assertCount($count, $events); self::assertEquals( [ - 'a/a.html', - 'b/b.html', - 'c.html', + [ + 'a/a.html', + [], + ], + [ + 'b/b.html', + [ + '../../../../README.md' => '../../../README.md', + '../a/excluded.txt' => 'a/excluded.txt', + ], + ], + [ + 'c.html', + [], + ], ], $taskA->processed, ); self::assertEquals( [ - 'a/a.html', - 'a/a.txt', - 'a/a/aa.txt', - 'a/b/ab.txt', - 'b/a/ba.txt', - 'b/b.html', - 'b/b.txt', - 'b/b/bb.txt', - 'c.htm', - 'c.html', - 'c.txt', + [ + 'a/a.html', + [], + ], + [ + 'a/a.txt', + [], + ], + [ + 'a/a/aa.txt', + [], + ], + [ + 'a/b/ab.txt', + [], + ], + [ + 'b/a/ba.txt', + [], + ], + [ + 'b/b.html', + [], + ], + [ + 'b/b.txt', + [], + ], + [ + 'b/b/bb.txt', + [], + ], + [ + 'c.htm', + [], + ], + [ + 'c.html', + [], + ], + [ + 'c.txt', + [], + ], ], $taskB->processed, ); } public function testRunFileNotFound(): void { - $task = new class() implements Task { - /** - * @inheritDoc - */ - #[Override] - public static function getExtensions(): array { - return ['txt']; - } - - /** - * @return Generator, mixed, bool> - */ - #[Override] - public function __invoke(Directory $root, File $file): Generator { - yield new FileReference('404.html'); - - return true; - } - }; - + $task = new ProcessorTest__Task(['*' => ['404.html']]); $root = (new DirectoryPath(self::getTestData()->path('')))->getNormalizedPath(); self::expectException(DependencyNotFound::class); @@ -451,32 +428,12 @@ public function __invoke(Directory $root, File $file): Generator { } public function testRunCircularDependency(): void { - $task = new class() implements Task { - /** - * @inheritDoc - */ - #[Override] - public static function getExtensions(): array { - return ['txt']; - } - - /** - * @return Generator, mixed, bool> - */ - #[Override] - public function __invoke(Directory $root, File $file): Generator { - match ($file->getName()) { - 'a.txt' => yield new FileReference('../b/b.txt'), - 'b.txt' => yield new FileReference('../b/a/ba.txt'), - 'ba.txt' => yield new FileReference('../../c.txt'), - 'c.txt' => yield new FileReference('a/a.txt'), - default => null, - }; - - return true; - } - }; - + $task = new ProcessorTest__Task([ + 'a.txt' => ['../b/b.txt'], + 'b.txt' => ['../b/a/ba.txt'], + 'ba.txt' => ['../../c.txt'], + 'c.txt' => ['a/a.txt'], + ]); $root = (new DirectoryPath(self::getTestData()->path('')))->getNormalizedPath(); self::expectException(CircularDependency::class); @@ -500,29 +457,9 @@ public function __invoke(Directory $root, File $file): Generator { } public function testRunCircularDependencySelf(): void { - $task = new class() implements Task { - /** - * @inheritDoc - */ - #[Override] - public static function getExtensions(): array { - return ['txt']; - } - - /** - * @return Generator, mixed, bool> - */ - #[Override] - public function __invoke(Directory $root, File $file): Generator { - match ($file->getName()) { - 'c.txt' => yield new FileReference('c.txt'), - default => null, - }; - - return true; - } - }; - + $task = new ProcessorTest__Task([ + 'c.txt' => ['c.txt'], + ]); $root = (new DirectoryPath(self::getTestData()->path('')))->getNormalizedPath(); self::expectException(CircularDependency::class); @@ -542,3 +479,62 @@ public function __invoke(Directory $root, File $file): Generator { ->run($root); } } + +// @phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses +// @phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps + +/** + * @internal + * @noinspection PhpMultipleClassesDeclarationsInOneFile + */ +class ProcessorTest__Task implements Task { + /** + * @var array}> + */ + public array $processed = []; + + public function __construct( + /** + * @var array> + */ + private readonly array $dependencies = [], + ) { + // empty + } + + /** + * @inheritDoc + */ + #[Override] + public static function getExtensions(): array { + return ['txt', 'md']; + } + + /** + * @return Generator, mixed, bool> + */ + #[Override] + public function __invoke(Directory $root, File $file): Generator { + $resolved = []; + $dependencies = $this->dependencies[$file->getName()] ?? $this->dependencies['*'] ?? []; + + foreach ($dependencies as $dependency) { + $resolved[$dependency] = yield new FileReference($dependency); + } + + $this->processed[] = [ + (string) $root->getRelativePath($file), + array_map( + static function (mixed $file) use ($root): mixed { + return (string) match (true) { + $file instanceof File => $root->getRelativePath($file), + default => null, + }; + }, + $resolved, + ), + ]; + + return true; + } +} From fa2a51241042b1342ad2a19a27dd31e11b29abae Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Sat, 7 Dec 2024 18:29:19 +0400 Subject: [PATCH 02/16] feat(documentator)!: `\LastDragon_ru\LaraASP\Documentator\Editor\Editor` to edit texts by coordinates (extracted from `\LastDragon_ru\LaraASP\Documentator\Markdown\Editor`). --- .../Location => Editor}/Coordinate.php | 2 +- .../src/{Markdown => Editor}/Editor.php | 61 ++++++++----------- .../src/{Markdown => Editor}/EditorTest.php | 23 ++++--- .../Location => Editor/Locations}/Append.php | 2 +- .../Locations}/Location.php | 3 +- .../Locations}/LocationTest.php | 3 +- .../src/Markdown/Contracts/Mutation.php | 2 +- .../src/Markdown/Data/Location.php | 2 +- .../documentator/src/Markdown/Document.php | 10 ++- .../src/Markdown/DocumentTest.php | 2 +- .../documentator/src/Markdown/Extension.php | 2 +- .../src/Markdown/ExtensionTest.php | 2 +- .../src/Markdown/Mutations/Changeset.php | 2 +- .../src/Markdown/Mutations/CompositeTest.php | 2 +- .../Mutations/Document/MakeInlinableTest.php | 2 +- .../Mutations/Document/MakeSplittableTest.php | 2 +- .../src/Markdown/Mutations/Document/Move.php | 6 +- .../Markdown/Mutations/Document/MoveTest.php | 2 +- .../Markdown/Mutations/Footnote/Prefix.php | 2 +- .../Mutations/Footnote/PrefixTest.php | 2 +- .../Markdown/Mutations/Footnote/Remove.php | 2 +- .../Mutations/Footnote/RemoveTest.php | 2 +- .../Mutations/Generated/UnwrapTest.php | 2 +- .../Markdown/Mutations/Heading/Renumber.php | 2 +- .../Mutations/Heading/RenumberTest.php | 2 +- .../Markdown/Mutations/Link/RemoveTest.php | 2 +- .../Mutations/Link/RemoveToSelfTest.php | 2 +- .../Mutations/Reference/InlineTest.php | 2 +- .../Markdown/Mutations/Reference/Prefix.php | 2 +- .../Mutations/Reference/PrefixTest.php | 2 +- .../Generated/Data/EndMarkerLocation.php | 2 +- .../Generated/Data/StartMarkerLocation.php | 2 +- .../Nodes/Generated/ParserContinue.php | 2 +- .../src/Markdown/Nodes/Locator/Parser.php | 2 +- .../src/Markdown/Nodes/RendererWrapper.php | 2 +- .../src/Markdown/Nodes/XmlRenderer.php | 2 +- .../src/Processor/Tasks/CodeLinks/Task.php | 4 +- .../Mutations/InstructionsRemoveTest.php | 2 +- .../Processor/Tasks/Preprocess/TaskTest.php | 2 +- 39 files changed, 88 insertions(+), 86 deletions(-) rename packages/documentator/src/{Markdown/Location => Editor}/Coordinate.php (79%) rename packages/documentator/src/{Markdown => Editor}/Editor.php (84%) rename packages/documentator/src/{Markdown => Editor}/EditorTest.php (93%) rename packages/documentator/src/{Markdown/Location => Editor/Locations}/Append.php (75%) rename packages/documentator/src/{Markdown/Location => Editor/Locations}/Location.php (95%) rename packages/documentator/src/{Markdown/Location => Editor/Locations}/LocationTest.php (92%) diff --git a/packages/documentator/src/Markdown/Location/Coordinate.php b/packages/documentator/src/Editor/Coordinate.php similarity index 79% rename from packages/documentator/src/Markdown/Location/Coordinate.php rename to packages/documentator/src/Editor/Coordinate.php index fda1f33d..73d1c13e 100644 --- a/packages/documentator/src/Markdown/Location/Coordinate.php +++ b/packages/documentator/src/Editor/Coordinate.php @@ -1,6 +1,6 @@ - */ - private array $lines, - private int $offset = 0, + /** + * @var list + */ + protected readonly array $lines; + + /** + * @param list|string $content + */ + final public function __construct( + array|string $content, + protected readonly int $startLine = 0, + protected readonly string $endOfLine = "\n", ) { - // empty + $this->lines = is_string($content) ? Text::getLines($content) : $content; } #[Override] public function __toString(): string { - return implode("\n", $this->lines); + return implode($this->endOfLine, $this->lines); } /** - * @return list + * @param iterable $location */ - public function getLines(): array { - return $this->lines; - } - - public function getOffset(): int { - return $this->offset; - } - - public function getText(Location|Coordinate $location): ?string { - // Coordinate? - if ($location instanceof Coordinate) { - $location = [$location]; - } - + public function getText(iterable $location): ?string { // Select $selected = null; foreach ($location as $coordinate) { - $number = $coordinate->line - $this->offset; + $number = $coordinate->line - $this->startLine; if (isset($this->lines[$number])) { $selected[] = mb_substr($this->lines[$number], $coordinate->offset, $coordinate->length); @@ -77,11 +69,11 @@ public function getText(Location|Coordinate $location): ?string { } // Return - return implode("\n", $selected); + return implode($this->endOfLine, $selected); } /** - * @param iterable $changes + * @param iterable, ?string}> $changes * * @return new */ @@ -100,7 +92,7 @@ public function mutate(iterable $changes): static { } // Change - $number = $coordinate->line - $this->offset; + $number = $coordinate->line - $this->startLine; $line = $lines[$number] ?? ''; $count = count($text); $prefix = mb_substr($line, 0, $coordinate->offset); @@ -131,14 +123,11 @@ public function mutate(iterable $changes): static { } // Return - $editor = clone $this; - $editor->lines = array_values($lines); - - return $editor; + return new static(array_values($lines), $this->startLine, $this->endOfLine); } /** - * @param iterable $changes + * @param iterable, ?string}> $changes * * @return list, ?string}> */ diff --git a/packages/documentator/src/Markdown/EditorTest.php b/packages/documentator/src/Editor/EditorTest.php similarity index 93% rename from packages/documentator/src/Markdown/EditorTest.php rename to packages/documentator/src/Editor/EditorTest.php index 6c71c184..40164233 100644 --- a/packages/documentator/src/Markdown/EditorTest.php +++ b/packages/documentator/src/Editor/EditorTest.php @@ -1,10 +1,9 @@ 'a b c d', 1 => 'e f g h', 2 => 'i j k l', @@ -38,8 +37,7 @@ public function testMutate(): void { 14 => '>', 15 => '>', ]; - $editor = new Editor($lines, 1); - $changes = [ + $changes = [ [new Location(1, 1, 2, 3), "123\n345\n567"], [new Location(2, 4, 4, 4), '123'], [new Location(6, 8, 4, 4), "123\n345"], @@ -49,6 +47,15 @@ public function testMutate(): void { [new Location(PHP_INT_MAX, PHP_INT_MAX), "added line a\n"], [new Location(PHP_INT_MAX, PHP_INT_MAX), "added line b\n"], ]; + $editor = new class($lines, 1) extends Editor { + /** + * @return list + */ + public function getLines(): array { + return $this->lines; + } + }; + $actual = $editor->mutate($changes); $expected = [ 'a 123', @@ -200,7 +207,7 @@ public function testGetText(): void { <<<'TEXT' f g TEXT, - $editor->getText(new Coordinate(2, 2, 3)), + $editor->getText([new Coordinate(2, 2, 3)]), ); } } diff --git a/packages/documentator/src/Markdown/Location/Append.php b/packages/documentator/src/Editor/Locations/Append.php similarity index 75% rename from packages/documentator/src/Markdown/Location/Append.php rename to packages/documentator/src/Editor/Locations/Append.php index d6a3cd9f..f3d30389 100644 --- a/packages/documentator/src/Markdown/Location/Append.php +++ b/packages/documentator/src/Editor/Locations/Append.php @@ -1,6 +1,6 @@ $location + */ + public function getText(iterable $location): ?string { return $this->getEditor()->getText($location); } diff --git a/packages/documentator/src/Markdown/DocumentTest.php b/packages/documentator/src/Markdown/DocumentTest.php index 82e61c03..edd41a4a 100644 --- a/packages/documentator/src/Markdown/DocumentTest.php +++ b/packages/documentator/src/Markdown/DocumentTest.php @@ -3,8 +3,8 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown; use LastDragon_ru\LaraASP\Core\Path\FilePath; +use LastDragon_ru\LaraASP\Documentator\Editor\Locations\Append; use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Mutation; -use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Append; use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Changeset; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; use Mockery; diff --git a/packages/documentator/src/Markdown/Extension.php b/packages/documentator/src/Markdown/Extension.php index dc29bb07..b30d29b2 100644 --- a/packages/documentator/src/Markdown/Extension.php +++ b/packages/documentator/src/Markdown/Extension.php @@ -2,8 +2,8 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown; +use LastDragon_ru\LaraASP\Documentator\Editor\Coordinate; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Input; -use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Coordinate; use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Generated\ParserStart as GenerateParser; use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Locator\Listener; use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Locator\Parser; diff --git a/packages/documentator/src/Markdown/ExtensionTest.php b/packages/documentator/src/Markdown/ExtensionTest.php index e8a7a6bb..f98a8ee3 100644 --- a/packages/documentator/src/Markdown/ExtensionTest.php +++ b/packages/documentator/src/Markdown/ExtensionTest.php @@ -2,9 +2,9 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown; +use LastDragon_ru\LaraASP\Documentator\Editor\Coordinate; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Lines; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Location; -use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Coordinate; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; use League\CommonMark\Extension\CommonMark\Node\Inline\Link; use League\CommonMark\GithubFlavoredMarkdownConverter; diff --git a/packages/documentator/src/Markdown/Mutations/Changeset.php b/packages/documentator/src/Markdown/Mutations/Changeset.php index 3eb96e05..34492ab9 100644 --- a/packages/documentator/src/Markdown/Mutations/Changeset.php +++ b/packages/documentator/src/Markdown/Mutations/Changeset.php @@ -2,9 +2,9 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations; +use LastDragon_ru\LaraASP\Documentator\Editor\Locations\Location; use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Mutation; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Location; use Override; /** diff --git a/packages/documentator/src/Markdown/Mutations/CompositeTest.php b/packages/documentator/src/Markdown/Mutations/CompositeTest.php index 8c2c56a8..f70d1c28 100644 --- a/packages/documentator/src/Markdown/Mutations/CompositeTest.php +++ b/packages/documentator/src/Markdown/Mutations/CompositeTest.php @@ -2,9 +2,9 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations; +use LastDragon_ru\LaraASP\Documentator\Editor\Locations\Location; use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Mutation; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Location; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; use League\CommonMark\Node\Block\Document as DocumentNode; use Mockery; diff --git a/packages/documentator/src/Markdown/Mutations/Document/MakeInlinableTest.php b/packages/documentator/src/Markdown/Mutations/Document/MakeInlinableTest.php index 0b0f8747..8c4c115d 100644 --- a/packages/documentator/src/Markdown/Mutations/Document/MakeInlinableTest.php +++ b/packages/documentator/src/Markdown/Mutations/Document/MakeInlinableTest.php @@ -3,8 +3,8 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Document; use LastDragon_ru\LaraASP\Core\Path\FilePath; +use LastDragon_ru\LaraASP\Documentator\Editor\Editor; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Editor; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; use League\CommonMark\Node\Block\Document as DocumentNode; use Override; diff --git a/packages/documentator/src/Markdown/Mutations/Document/MakeSplittableTest.php b/packages/documentator/src/Markdown/Mutations/Document/MakeSplittableTest.php index d8abe65e..65dac476 100644 --- a/packages/documentator/src/Markdown/Mutations/Document/MakeSplittableTest.php +++ b/packages/documentator/src/Markdown/Mutations/Document/MakeSplittableTest.php @@ -3,8 +3,8 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Document; use LastDragon_ru\LaraASP\Core\Path\FilePath; +use LastDragon_ru\LaraASP\Documentator\Editor\Editor; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Editor; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; use League\CommonMark\Node\Block\Document as DocumentNode; use Override; diff --git a/packages/documentator/src/Markdown/Mutations/Document/Move.php b/packages/documentator/src/Markdown/Mutations/Document/Move.php index df4a24ba..50f66728 100644 --- a/packages/documentator/src/Markdown/Mutations/Document/Move.php +++ b/packages/documentator/src/Markdown/Mutations/Document/Move.php @@ -4,12 +4,12 @@ use Iterator; use LastDragon_ru\LaraASP\Core\Path\FilePath; +use LastDragon_ru\LaraASP\Documentator\Editor\Coordinate; use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Mutation; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Location; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Offset; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Reference; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Coordinate; use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Reference\Block as ReferenceNode; use LastDragon_ru\LaraASP\Documentator\Markdown\Utils; use League\CommonMark\Extension\CommonMark\Node\Inline\AbstractWebResource; @@ -97,14 +97,14 @@ public function __invoke(Document $document): iterable { if ($location->startLine !== $location->endLine) { $padding = $location->internalPadding ?? $location->startLinePadding; - $last = $document->getText( + $last = $document->getText([ new Coordinate( $location->endLine, $padding, $location->length, $padding, ), - ); + ]); if ($last === '') { $text .= "\n"; diff --git a/packages/documentator/src/Markdown/Mutations/Document/MoveTest.php b/packages/documentator/src/Markdown/Mutations/Document/MoveTest.php index f56b65dc..bbd8a14a 100644 --- a/packages/documentator/src/Markdown/Mutations/Document/MoveTest.php +++ b/packages/documentator/src/Markdown/Mutations/Document/MoveTest.php @@ -3,8 +3,8 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Document; use LastDragon_ru\LaraASP\Core\Path\FilePath; +use LastDragon_ru\LaraASP\Documentator\Editor\Editor; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Editor; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; use League\CommonMark\Node\Block\Document as DocumentNode; use Override; diff --git a/packages/documentator/src/Markdown/Mutations/Footnote/Prefix.php b/packages/documentator/src/Markdown/Mutations/Footnote/Prefix.php index 2d4b35a9..b41d039c 100644 --- a/packages/documentator/src/Markdown/Mutations/Footnote/Prefix.php +++ b/packages/documentator/src/Markdown/Mutations/Footnote/Prefix.php @@ -2,10 +2,10 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Footnote; +use LastDragon_ru\LaraASP\Documentator\Editor\Locations\Location; use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Mutation; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Location as LocationData; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Location; use League\CommonMark\Extension\Footnote\Node\Footnote; use League\CommonMark\Extension\Footnote\Node\FootnoteRef; use Override; diff --git a/packages/documentator/src/Markdown/Mutations/Footnote/PrefixTest.php b/packages/documentator/src/Markdown/Mutations/Footnote/PrefixTest.php index dbf2f876..c05bc523 100644 --- a/packages/documentator/src/Markdown/Mutations/Footnote/PrefixTest.php +++ b/packages/documentator/src/Markdown/Mutations/Footnote/PrefixTest.php @@ -3,8 +3,8 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Footnote; use LastDragon_ru\LaraASP\Core\Path\FilePath; +use LastDragon_ru\LaraASP\Documentator\Editor\Editor; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Editor; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; use League\CommonMark\Node\Block\Document as DocumentNode; use Override; diff --git a/packages/documentator/src/Markdown/Mutations/Footnote/Remove.php b/packages/documentator/src/Markdown/Mutations/Footnote/Remove.php index cb630e7b..cfd3fe61 100644 --- a/packages/documentator/src/Markdown/Mutations/Footnote/Remove.php +++ b/packages/documentator/src/Markdown/Mutations/Footnote/Remove.php @@ -2,10 +2,10 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Footnote; +use LastDragon_ru\LaraASP\Documentator\Editor\Locations\Location; use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Mutation; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Location as LocationData; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Location; use League\CommonMark\Extension\Footnote\Node\Footnote; use League\CommonMark\Extension\Footnote\Node\FootnoteRef; use Override; diff --git a/packages/documentator/src/Markdown/Mutations/Footnote/RemoveTest.php b/packages/documentator/src/Markdown/Mutations/Footnote/RemoveTest.php index 421071da..2d6173d8 100644 --- a/packages/documentator/src/Markdown/Mutations/Footnote/RemoveTest.php +++ b/packages/documentator/src/Markdown/Mutations/Footnote/RemoveTest.php @@ -2,8 +2,8 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Footnote; +use LastDragon_ru\LaraASP\Documentator\Editor\Editor; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Editor; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; use League\CommonMark\Node\Block\Document as DocumentNode; use Override; diff --git a/packages/documentator/src/Markdown/Mutations/Generated/UnwrapTest.php b/packages/documentator/src/Markdown/Mutations/Generated/UnwrapTest.php index 719adb7b..aa8e549e 100644 --- a/packages/documentator/src/Markdown/Mutations/Generated/UnwrapTest.php +++ b/packages/documentator/src/Markdown/Mutations/Generated/UnwrapTest.php @@ -2,8 +2,8 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Generated; +use LastDragon_ru\LaraASP\Documentator\Editor\Editor; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Editor; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; use League\CommonMark\Node\Block\Document as DocumentNode; use Override; diff --git a/packages/documentator/src/Markdown/Mutations/Heading/Renumber.php b/packages/documentator/src/Markdown/Mutations/Heading/Renumber.php index 72410ada..7ffdff1e 100644 --- a/packages/documentator/src/Markdown/Mutations/Heading/Renumber.php +++ b/packages/documentator/src/Markdown/Mutations/Heading/Renumber.php @@ -2,10 +2,10 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Heading; +use LastDragon_ru\LaraASP\Documentator\Editor\Locations\Location; use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Mutation; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Location as LocationData; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Location; use League\CommonMark\Extension\CommonMark\Node\Block\Heading; use Override; diff --git a/packages/documentator/src/Markdown/Mutations/Heading/RenumberTest.php b/packages/documentator/src/Markdown/Mutations/Heading/RenumberTest.php index 8c93660e..c695c926 100644 --- a/packages/documentator/src/Markdown/Mutations/Heading/RenumberTest.php +++ b/packages/documentator/src/Markdown/Mutations/Heading/RenumberTest.php @@ -2,8 +2,8 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Heading; +use LastDragon_ru\LaraASP\Documentator\Editor\Editor; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Editor; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; use League\CommonMark\Node\Block\Document as DocumentNode; use Override; diff --git a/packages/documentator/src/Markdown/Mutations/Link/RemoveTest.php b/packages/documentator/src/Markdown/Mutations/Link/RemoveTest.php index fe9110df..bd34720f 100644 --- a/packages/documentator/src/Markdown/Mutations/Link/RemoveTest.php +++ b/packages/documentator/src/Markdown/Mutations/Link/RemoveTest.php @@ -3,8 +3,8 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Link; use LastDragon_ru\LaraASP\Core\Path\FilePath; +use LastDragon_ru\LaraASP\Documentator\Editor\Editor; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Editor; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; use League\CommonMark\Node\Block\Document as DocumentNode; use Override; diff --git a/packages/documentator/src/Markdown/Mutations/Link/RemoveToSelfTest.php b/packages/documentator/src/Markdown/Mutations/Link/RemoveToSelfTest.php index 78415d4d..d32440e6 100644 --- a/packages/documentator/src/Markdown/Mutations/Link/RemoveToSelfTest.php +++ b/packages/documentator/src/Markdown/Mutations/Link/RemoveToSelfTest.php @@ -3,8 +3,8 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Link; use LastDragon_ru\LaraASP\Core\Path\FilePath; +use LastDragon_ru\LaraASP\Documentator\Editor\Editor; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Editor; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; use League\CommonMark\Node\Block\Document as DocumentNode; use Override; diff --git a/packages/documentator/src/Markdown/Mutations/Reference/InlineTest.php b/packages/documentator/src/Markdown/Mutations/Reference/InlineTest.php index 48be271d..af8f35b9 100644 --- a/packages/documentator/src/Markdown/Mutations/Reference/InlineTest.php +++ b/packages/documentator/src/Markdown/Mutations/Reference/InlineTest.php @@ -2,8 +2,8 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Reference; +use LastDragon_ru\LaraASP\Documentator\Editor\Editor; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Editor; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; use League\CommonMark\Node\Block\Document as DocumentNode; use Override; diff --git a/packages/documentator/src/Markdown/Mutations/Reference/Prefix.php b/packages/documentator/src/Markdown/Mutations/Reference/Prefix.php index 4db7af98..58640455 100644 --- a/packages/documentator/src/Markdown/Mutations/Reference/Prefix.php +++ b/packages/documentator/src/Markdown/Mutations/Reference/Prefix.php @@ -3,12 +3,12 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Reference; use Iterator; +use LastDragon_ru\LaraASP\Documentator\Editor\Locations\Location; use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Mutation; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Location as LocationData; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Offset as OffsetData; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Reference as ReferenceData; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Location; use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Reference\Block as ReferenceNode; use LastDragon_ru\LaraASP\Documentator\Markdown\Utils; use League\CommonMark\Extension\CommonMark\Node\Inline\AbstractWebResource; diff --git a/packages/documentator/src/Markdown/Mutations/Reference/PrefixTest.php b/packages/documentator/src/Markdown/Mutations/Reference/PrefixTest.php index b82fb6f9..471b8e3b 100644 --- a/packages/documentator/src/Markdown/Mutations/Reference/PrefixTest.php +++ b/packages/documentator/src/Markdown/Mutations/Reference/PrefixTest.php @@ -3,8 +3,8 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Reference; use LastDragon_ru\LaraASP\Core\Path\FilePath; +use LastDragon_ru\LaraASP\Documentator\Editor\Editor; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Editor; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; use League\CommonMark\Node\Block\Document as DocumentNode; use Override; diff --git a/packages/documentator/src/Markdown/Nodes/Generated/Data/EndMarkerLocation.php b/packages/documentator/src/Markdown/Nodes/Generated/Data/EndMarkerLocation.php index b3cb228d..b45ccd38 100644 --- a/packages/documentator/src/Markdown/Nodes/Generated/Data/EndMarkerLocation.php +++ b/packages/documentator/src/Markdown/Nodes/Generated/Data/EndMarkerLocation.php @@ -2,8 +2,8 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Generated\Data; +use LastDragon_ru\LaraASP\Documentator\Editor\Locations\Location; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Data; -use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Location; /** * @internal diff --git a/packages/documentator/src/Markdown/Nodes/Generated/Data/StartMarkerLocation.php b/packages/documentator/src/Markdown/Nodes/Generated/Data/StartMarkerLocation.php index 8e4f45f6..562d9232 100644 --- a/packages/documentator/src/Markdown/Nodes/Generated/Data/StartMarkerLocation.php +++ b/packages/documentator/src/Markdown/Nodes/Generated/Data/StartMarkerLocation.php @@ -2,8 +2,8 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Generated\Data; +use LastDragon_ru\LaraASP\Documentator\Editor\Locations\Location; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Data; -use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Location; /** * @internal diff --git a/packages/documentator/src/Markdown/Nodes/Generated/ParserContinue.php b/packages/documentator/src/Markdown/Nodes/Generated/ParserContinue.php index f03954f3..68fa05ea 100644 --- a/packages/documentator/src/Markdown/Nodes/Generated/ParserContinue.php +++ b/packages/documentator/src/Markdown/Nodes/Generated/ParserContinue.php @@ -2,8 +2,8 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Generated; +use LastDragon_ru\LaraASP\Documentator\Editor\Locations\Location; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\BlockPadding; -use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Location; use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Generated\Data\EndMarkerLocation; use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Generated\Data\StartMarkerLocation; use League\CommonMark\Node\Block\AbstractBlock; diff --git a/packages/documentator/src/Markdown/Nodes/Locator/Parser.php b/packages/documentator/src/Markdown/Nodes/Locator/Parser.php index f312320d..fbffe8b8 100644 --- a/packages/documentator/src/Markdown/Nodes/Locator/Parser.php +++ b/packages/documentator/src/Markdown/Nodes/Locator/Parser.php @@ -2,11 +2,11 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Locator; +use LastDragon_ru\LaraASP\Documentator\Editor\Locations\Location; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\BlockPadding as DataBlockPadding; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Location as LocationData; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Offset as OffsetData; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Padding as PaddingData; -use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Location; use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Aware; use LastDragon_ru\LaraASP\Documentator\Markdown\Utils; use LastDragon_ru\LaraASP\Documentator\Utils\Text; diff --git a/packages/documentator/src/Markdown/Nodes/RendererWrapper.php b/packages/documentator/src/Markdown/Nodes/RendererWrapper.php index 505fb41c..40af6321 100644 --- a/packages/documentator/src/Markdown/Nodes/RendererWrapper.php +++ b/packages/documentator/src/Markdown/Nodes/RendererWrapper.php @@ -2,12 +2,12 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Nodes; +use LastDragon_ru\LaraASP\Documentator\Editor\Locations\Location; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\BlockPadding as BlockPaddingData; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Length as LengthData; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Location as LocationData; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Offset as OffsetData; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Padding as PaddingData; -use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Location; use League\CommonMark\Environment\EnvironmentAwareInterface; use League\CommonMark\Node\Node; use League\CommonMark\Renderer\ChildNodeRendererInterface; diff --git a/packages/documentator/src/Markdown/Nodes/XmlRenderer.php b/packages/documentator/src/Markdown/Nodes/XmlRenderer.php index b3d50c22..8030369a 100644 --- a/packages/documentator/src/Markdown/Nodes/XmlRenderer.php +++ b/packages/documentator/src/Markdown/Nodes/XmlRenderer.php @@ -2,7 +2,7 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Nodes; -use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Location; +use LastDragon_ru\LaraASP\Documentator\Editor\Locations\Location; use League\CommonMark\Node\Node; /** diff --git a/packages/documentator/src/Processor/Tasks/CodeLinks/Task.php b/packages/documentator/src/Processor/Tasks/CodeLinks/Task.php index 20cab93d..1fac08d4 100644 --- a/packages/documentator/src/Processor/Tasks/CodeLinks/Task.php +++ b/packages/documentator/src/Processor/Tasks/CodeLinks/Task.php @@ -5,10 +5,10 @@ use Generator; use LastDragon_ru\LaraASP\Core\Utils\Cast; use LastDragon_ru\LaraASP\Documentator\Composer\Package; +use LastDragon_ru\LaraASP\Documentator\Editor\Locations\Append; +use LastDragon_ru\LaraASP\Documentator\Editor\Locations\Location; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Location as LocationData; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Append; -use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Location; use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Changeset; use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Generated\Block as GeneratedNode; use LastDragon_ru\LaraASP\Documentator\Markdown\Utils; diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Mutations/InstructionsRemoveTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/Mutations/InstructionsRemoveTest.php index 5a8a9d53..c91b4222 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Mutations/InstructionsRemoveTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Mutations/InstructionsRemoveTest.php @@ -2,8 +2,8 @@ namespace LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Mutations; +use LastDragon_ru\LaraASP\Documentator\Editor\Editor; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Editor; use LastDragon_ru\LaraASP\Documentator\Processor\InstanceList; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; use League\CommonMark\Node\Block\Document as DocumentNode; diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/TaskTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/TaskTest.php index 9d854458..0adafb42 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/TaskTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/TaskTest.php @@ -4,9 +4,9 @@ use LastDragon_ru\LaraASP\Core\Application\ContainerResolver; use LastDragon_ru\LaraASP\Core\Path\FilePath; +use LastDragon_ru\LaraASP\Documentator\Editor\Locations\Location; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Location as LocationData; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Location; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File; use LastDragon_ru\LaraASP\Documentator\Processor\Metadata\Markdown; From 8ca1ae84f03d5998e6e06af2c58c607afdab556a Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Mon, 9 Dec 2024 09:21:04 +0400 Subject: [PATCH 03/16] feat(documentator)!: `\LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown` contract to create `\LastDragon_ru\LaraASP\Documentator\Markdown\Document` instance. --- .../documentator/src/Commands/Commands.php | 12 +- .../documentator/src/Commands/Preprocess.php | 8 +- .../src/Markdown/Contracts/Markdown.php | 10 + .../documentator/src/Markdown/Document.php | 78 +-- .../src/Markdown/DocumentTest.php | 459 +++++++++--------- .../documentator/src/Markdown/Markdown.php | 35 ++ .../src/Markdown/Mutations/CompositeTest.php | 12 +- .../Mutations/Document/MakeInlinableTest.php | 34 +- .../Mutations/Document/MakeSplittableTest.php | 33 +- .../src/Markdown/Mutations/Document/Move.php | 8 +- .../Markdown/Mutations/Document/MoveTest.php | 38 +- .../Markdown/Mutations/Footnote/Prefix.php | 2 +- .../Mutations/Footnote/PrefixTest.php | 34 +- .../Markdown/Mutations/Footnote/Remove.php | 2 +- .../Mutations/Footnote/RemoveTest.php | 33 +- .../Markdown/Mutations/Generated/Unwrap.php | 2 +- .../Mutations/Generated/UnwrapTest.php | 34 +- .../Markdown/Mutations/Heading/Renumber.php | 2 +- .../Mutations/Heading/RenumberTest.php | 34 +- .../src/Markdown/Mutations/Link/Remove.php | 2 +- .../Markdown/Mutations/Link/RemoveTest.php | 34 +- .../Mutations/Link/RemoveToSelfTest.php | 34 +- .../Markdown/Mutations/Reference/Inline.php | 2 +- .../Mutations/Reference/InlineTest.php | 34 +- .../Markdown/Mutations/Reference/Prefix.php | 2 +- .../Mutations/Reference/PrefixTest.php | 34 +- packages/documentator/src/Markdown/Utils.php | 2 +- .../documentator/src/Markdown/UtilsTest.php | 6 +- packages/documentator/src/PackageProvider.php | 3 + .../src/Processor/Metadata/Markdown.php | 7 +- .../Processor/Metadata/PhpClassMarkdown.php | 6 +- .../Metadata/PhpClassMarkdownTest.php | 12 +- .../src/Processor/Metadata/PhpDocBlock.php | 4 +- .../Processor/Metadata/PhpDocBlockTest.php | 10 +- .../src/Processor/Tasks/CodeLinks/Task.php | 4 +- .../Processor/Tasks/CodeLinks/TaskTest.php | 3 +- .../Processor/Tasks/Preprocess/Context.php | 2 +- .../IncludeArtisan/InstructionTest.php | 6 +- .../IncludeDocBlock/InstructionTest.php | 5 +- .../IncludeDocumentList/InstructionTest.php | 6 +- .../IncludeExample/Instruction.php | 5 +- .../IncludeExample/InstructionTest.php | 5 +- .../IncludeExec/InstructionTest.php | 3 +- .../IncludeFile/InstructionTest.php | 3 +- .../InstructionTest.php | 8 +- .../IncludePackageList/InstructionTest.php | 7 +- .../IncludeTemplate/Instruction.php | 7 +- .../IncludeTemplate/InstructionTest.php | 9 +- .../Mutations/InstructionsRemove.php | 2 +- .../Mutations/InstructionsRemoveTest.php | 33 +- .../src/Processor/Tasks/Preprocess/Task.php | 2 +- .../Processor/Tasks/Preprocess/TaskTest.php | 21 +- .../src/Processor/Tasks/Preprocess/Utils.php | 2 +- packages/documentator/src/Utils/PhpDoc.php | 36 -- .../src/Utils/PhpDocumentFactory.php | 55 ++- 55 files changed, 543 insertions(+), 743 deletions(-) create mode 100644 packages/documentator/src/Markdown/Contracts/Markdown.php create mode 100644 packages/documentator/src/Markdown/Markdown.php diff --git a/packages/documentator/src/Commands/Commands.php b/packages/documentator/src/Commands/Commands.php index 8a93d2f8..d386b00d 100644 --- a/packages/documentator/src/Commands/Commands.php +++ b/packages/documentator/src/Commands/Commands.php @@ -6,7 +6,7 @@ use Illuminate\Support\Str; use LastDragon_ru\LaraASP\Core\Path\DirectoryPath; use LastDragon_ru\LaraASP\Core\Utils\Cast; -use LastDragon_ru\LaraASP\Documentator\Markdown\Document; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Document\Move; use LastDragon_ru\LaraASP\Documentator\Package; use LastDragon_ru\LaraASP\Documentator\PackageViewer; @@ -36,7 +36,12 @@ class Commands extends Command { {--defaults : Include application default arguments/options like `--help`, etc.} SIGNATURE; - public function __invoke(PackageViewer $viewer, Filesystem $filesystem, ArtisanSerializer $serializer): void { + public function __invoke( + PackageViewer $viewer, + Filesystem $filesystem, + Markdown $markdown, + ArtisanSerializer $serializer, + ): void { // Options $application = Cast::to(Application::class, $this->getApplication()); $namespace = $application->findNamespace(Cast::toString($this->argument('namespace'))); @@ -68,6 +73,7 @@ static function () use ($filesystem, $target): void { $this->components->task( "Command: {$command->getName()}", static function () use ( + $markdown, $filesystem, $serializer, $viewer, @@ -94,7 +100,7 @@ static function () use ( 'serializer' => $serializer, 'command' => $command, ]); - $content = (string) (new Document($content, $source))->mutate( + $content = (string) $markdown->parse($content, $source)->mutate( new Move($path), ); diff --git a/packages/documentator/src/Commands/Preprocess.php b/packages/documentator/src/Commands/Preprocess.php index cde668b8..3a934275 100644 --- a/packages/documentator/src/Commands/Preprocess.php +++ b/packages/documentator/src/Commands/Preprocess.php @@ -333,7 +333,13 @@ private function getDocBlock( ): string { // Load $this->phpDocumentFactory ??= $this->laravel->make(PhpDocumentFactory::class); - $help = ($this->phpDocumentFactory)($object); + $phpdoc = new PhpDoc((string) $object->getDocComment()); + $path = match (true) { + $object instanceof ReflectionProperty => $object->getDeclaringClass()->getFileName(), + default => $object->getFileName(), + }; + $path = $path !== false ? new FilePath($path) : null; + $help = ($this->phpDocumentFactory)($phpdoc, $path); // Move to cwd $cwd = new DirectoryPath((string) getcwd()); diff --git a/packages/documentator/src/Markdown/Contracts/Markdown.php b/packages/documentator/src/Markdown/Contracts/Markdown.php new file mode 100644 index 00000000..496bb012 --- /dev/null +++ b/packages/documentator/src/Markdown/Contracts/Markdown.php @@ -0,0 +1,10 @@ +setContent($content); - $this->setPath($path); + public function __construct( + protected readonly Markdown $markdown, + public readonly DocumentNode $node, + public ?FilePath $path = null, + ) { + // empty } public function isEmpty(): bool { - return !$this->getNode()->hasChildren() && count($this->getNode()->getReferenceMap()) === 0; + return !$this->node->hasChildren() && count($this->node->getReferenceMap()) === 0; } /** - * Returns the first `# Header` if present, the title based on filename - * if known, or `null`. + * Returns the first `# Header` if present. */ public function getTitle(): ?string { if ($this->title === null) { @@ -98,16 +94,6 @@ public function getBody(): ?string { return $body; } - public function getPath(): ?FilePath { - return $this->path; - } - - public function setPath(?FilePath $path): static { - $this->path = $path; - - return $this; - } - /** * @param iterable $location */ @@ -115,45 +101,23 @@ public function getText(iterable $location): ?string { return $this->getEditor()->getText($location); } - /** - * @return new - */ - public function mutate(Mutation ...$mutations): static { + public function mutate(Mutation ...$mutations): self { $document = clone $this; foreach ($mutations as $mutation) { $changes = $mutation($document); $content = trim((string) $document->getEditor()->mutate($changes))."\n"; - $document = $document->setContent($content); + $document = $this->markdown->parse($content, $document->path); } return $document; } - protected function setContent(string $content): static { - $this->node = $content; - $this->title = null; - $this->summary = null; - $this->editor = null; - - return $this; - } - - protected function parse(string $string): DocumentNode { - if (!isset($this->parser)) { - $converter = new GithubFlavoredMarkdownConverter(); - $environment = $converter->getEnvironment()->addExtension(new Extension()); - $this->parser = new MarkdownParser($environment); - } - - return $this->parser->parse($string); - } - /** * @return array */ protected function getLines(): array { - return Lines::get($this->getNode()); + return Lines::get($this->node); } protected function getEditor(): Editor { @@ -166,14 +130,6 @@ protected function getEditor(): Editor { return $this->editor; } - public function getNode(): DocumentNode { - if (is_string($this->node)) { - $this->node = $this->parse($this->node); - } - - return $this->node; - } - /** * @template T of Node * @@ -186,7 +142,7 @@ public function getNode(): DocumentNode { private function getFirstNode(string $class, ?Closure $filter = null, ?Closure $skip = null): ?Node { $node = null; - foreach ($this->getNode()->children() as $child) { + foreach ($this->node->children() as $child) { // Comment? if ( $child instanceof HtmlBlock @@ -239,6 +195,6 @@ private function getSummaryNode(): ?Paragraph { #[Override] public function __toString(): string { - return is_string($this->node) ? $this->node : implode("\n", $this->getLines())."\n"; + return implode("\n", $this->getLines())."\n"; } } diff --git a/packages/documentator/src/Markdown/DocumentTest.php b/packages/documentator/src/Markdown/DocumentTest.php index edd41a4a..81f803b2 100644 --- a/packages/documentator/src/Markdown/DocumentTest.php +++ b/packages/documentator/src/Markdown/DocumentTest.php @@ -2,64 +2,129 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown; -use LastDragon_ru\LaraASP\Core\Path\FilePath; use LastDragon_ru\LaraASP\Documentator\Editor\Locations\Append; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Mutation; use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Changeset; +use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Nop; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; use Mockery; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; /** * @internal */ #[CoversClass(Document::class)] final class DocumentTest extends TestCase { - public function testGetTitle(): void { - self::assertNull( - (new Document( + // + // ========================================================================= + #[DataProvider('dataProviderGetTitle')] + public function testGetTitle(?string $expected, string $content): void { + $markdown = $this->app()->make(Markdown::class); + $document = $markdown->parse($content); + $actual = $document->getTitle(); + + self::assertEquals($expected, $actual); + } + + #[DataProvider('dataProviderGetSummary')] + public function testGetSummary(?string $expected, string $content): void { + $markdown = $this->app()->make(Markdown::class); + $document = $markdown->parse($content); + $actual = $document->getSummary(); + + self::assertEquals($expected, $actual); + } + + #[DataProvider('dataProviderGetBody')] + public function testGetBody(?string $expected, string $content): void { + $markdown = $this->app()->make(Markdown::class); + $document = $markdown->parse($content); + $actual = $document->getBody(); + + self::assertEquals($expected, $actual); + } + + #[DataProvider('dataProviderIsEmpty')] + public function testIsEmpty(bool $expected, string $content): void { + $markdown = $this->app()->make(Markdown::class); + $document = $markdown->parse($content); + $actual = $document->isEmpty(); + + self::assertEquals($expected, $actual); + } + + public function testMutate(): void { + $markdown = $this->app()->make(Markdown::class); + $document = $markdown->parse(''); + $mutation = Mockery::mock(Mutation::class); + $mutation + ->shouldReceive('__invoke') + ->with(Mockery::type(Document::class)) + ->once() + ->andReturn([ + // empty + ]); + + $clone = clone $document; + $mutated = $document->mutate($mutation); + + self::assertNotSame($document, $mutated); + self::assertEquals($clone, $document); + } + + #[DataProvider('dataProviderToString')] + public function testToString(string $expected, string $content, ?Mutation $mutation): void { + $markdown = $this->app()->make(Markdown::class); + $document = $markdown->parse($content)->mutate($mutation ?? new Nop()); + $actual = (string) $document; + + self::assertEquals($expected, $actual); + } + // + + // + // ========================================================================= + /** + * @return array + */ + public static function dataProviderGetTitle(): array { + return [ + 'No #' => [ + null, <<<'MARKDOWN' ## Header A # Header B MARKDOWN, - )) - ->getTitle(), - ); - self::assertNull( - (new Document( + ], + 'The # is not first' => [ + null, <<<'MARKDOWN' fsdfsdfsdf # Header MARKDOWN, - )) - ->getTitle(), - ); - self::assertNull( - (new Document( + ], + 'The # is empty' => [ + null, <<<'MARKDOWN' # fsdfsdfsdf MARKDOWN, - )) - ->getTitle(), - ); - self::assertEquals( - 'Header', - (new Document( + ], + 'Empty line before #' => [ + 'Header', <<<'MARKDOWN' # Header fsdfsdfsdf MARKDOWN, - )) - ->getTitle(), - ); - self::assertEquals( - 'Header', - (new Document( + ], + 'Comment before #' => [ + 'Header', <<<'MARKDOWN' @@ -67,35 +132,26 @@ public function testGetTitle(): void { fsdfsdfsdf MARKDOWN, - )) - ->getTitle(), - ); - self::assertNull( - (new Document( - <<<'MARKDOWN' - fsdfsdfsdf - MARKDOWN, - new FilePath('path/to/FileName.txt'), - )) - ->getTitle(), - ); + ], + ]; } - public function testGetSummary(): void { - self::assertNull( - (new Document( + /** + * @return array + */ + public static function dataProviderGetSummary(): array { + return [ + 'The # is not first' => [ + null, <<<'MARKDOWN' ## Header A # Header B sdfsdfsdf MARKDOWN, - )) - ->getSummary(), - ); - self::assertEquals( - 'fsdfsdfsdf', - (new Document( + ], + 'Summary is the first node' => [ + 'fsdfsdfsdf', <<<'MARKDOWN' fsdfsdfsdf @@ -103,11 +159,9 @@ public function testGetSummary(): void { sdfsdfsdf MARKDOWN, - )) - ->getSummary(), - ); - self::assertNull( - (new Document( + ], + 'Quote before #' => [ + null, <<<'MARKDOWN' # Header @@ -115,26 +169,20 @@ public function testGetSummary(): void { fsdfsdfsdf MARKDOWN, - )) - ->getSummary(), - ); - self::assertEquals( - 'fsdfsdfsdf', - (new Document( + ], + 'Empty #' => [ + 'fsdfsdfsdf', <<<'MARKDOWN' # fsdfsdfsdf MARKDOWN, - )) - ->getSummary(), - ); - self::assertEquals( - <<<'TEXT' - fsdfsdfsdf - fsdfsdfsdf - TEXT, - (new Document( + ], + 'Multiline' => [ + <<<'TEXT' + fsdfsdfsdf + fsdfsdfsdf + TEXT, <<<'MARKDOWN' # Header @@ -142,15 +190,12 @@ public function testGetSummary(): void { fsdfsdfsdf fsdfsdfsdf MARKDOWN, - )) - ->getSummary(), - ); - self::assertEquals( - <<<'TEXT' - fsdfsdfsdf - fsdfsdfsdf - TEXT, - (new Document( + ], + 'Comments should be ignored' => [ + <<<'TEXT' + fsdfsdfsdf + fsdfsdfsdf + TEXT, <<<'MARKDOWN' @@ -161,30 +206,30 @@ public function testGetSummary(): void { fsdfsdfsdf fsdfsdfsdf MARKDOWN, - )) - ->getSummary(), - ); + ], + ]; } - public function testGetBody(): void { - self::assertNull( - (new Document( + /** + * @return array + */ + public static function dataProviderGetBody(): array { + return [ + 'The # is not first' => [ + null, <<<'MARKDOWN' ## Header A # Header B sdfsdfsdf MARKDOWN, - )) - ->getBody(), - ); - self::assertEquals( - <<<'MARKDOWN' - # Header + ], + 'Summary is the first node' => [ + <<<'TEXT' + # Header - sdfsdfsdf - MARKDOWN, - (new Document( + sdfsdfsdf + TEXT, <<<'MARKDOWN' fsdfsdfsdf @@ -192,11 +237,9 @@ public function testGetBody(): void { sdfsdfsdf MARKDOWN, - )) - ->getBody(), - ); - self::assertNull( - (new Document( + ], + 'Quote before #' => [ + null, <<<'MARKDOWN' # Header @@ -206,16 +249,13 @@ public function testGetBody(): void { text text text MARKDOWN, - )) - ->getBody(), - ); - self::assertEquals( - <<<'MARKDOWN' - text text text + ], + 'Empty #' => [ + <<<'TEXT' + text text text - text text text - MARKDOWN, - (new Document( + text text text + TEXT, <<<'MARKDOWN' # @@ -225,16 +265,13 @@ public function testGetBody(): void { text text text MARKDOWN, - )) - ->getBody(), - ); - self::assertEquals( - <<<'MARKDOWN' - text text text + ], + 'Multiline summary' => [ + <<<'TEXT' + text text text - text text text - MARKDOWN, - (new Document( + text text text + TEXT, <<<'MARKDOWN' # Header @@ -246,16 +283,13 @@ public function testGetBody(): void { text text text MARKDOWN, - )) - ->getBody(), - ); - self::assertEquals( - <<<'MARKDOWN' - + ], + 'Comments should be ignored' => [ + <<<'TEXT' + - text text text - MARKDOWN, - (new Document( + text text text + TEXT, <<<'MARKDOWN' @@ -263,159 +297,134 @@ public function testGetBody(): void { - text text text + summary text text text MARKDOWN, - )) - ->getBody(), - ); + ], + ]; } - public function testIsEmpty(): void { - self::assertFalse( - (new Document( + /** + * @return array + */ + public static function dataProviderIsEmpty(): array { + return [ + 'Empty' => [ + true, + <<<'MARKDOWN' + + + + MARKDOWN, + ], + 'Not empty' => [ + false, <<<'MARKDOWN' fsdfsdfsdf fsdfsdfsdf MARKDOWN, - )) - ->isEmpty(), - ); - self::assertFalse( - (new Document( + ], + 'Reference only' => [ + false, <<<'MARKDOWN' [unused]: ../path/to/file MARKDOWN, - )) - ->isEmpty(), - ); - self::assertFalse( - (new Document( + ], + 'Comment only' => [ + false, <<<'MARKDOWN' MARKDOWN, - )) - ->isEmpty(), - ); - self::assertTrue( - (new Document( - <<<'MARKDOWN' - - - - MARKDOWN, - )) - ->isEmpty(), - ); + ], + ]; } - public function testMutate(): void { - $document = new Document(''); - $mutation = Mockery::mock(Mutation::class); - $mutation - ->shouldReceive('__invoke') - ->with(Mockery::type(Document::class)) - ->once() - ->andReturn([ - // empty - ]); - - $clone = clone $document; - $mutated = $document->mutate($mutation); - - self::assertNotSame($document, $mutated); - self::assertEquals($clone, $document); - } + /** + * @return array + */ + public static function dataProviderToString(): array { + return [ + 'Blank line on the end' => [ + <<<'MARKDOWN' + fsdfsdfsdf + fsdfsdfsdf - public function testToString(): void { - self::assertEquals( - <<<'MARKDOWN' - fsdfsdfsdf - fsdfsdfsdf + MARKDOWN, + <<<'MARKDOWN' + fsdfsdfsdf + fsdfsdfsdf - MARKDOWN, - (string) (new Document( + MARKDOWN, + null, + ], + 'No blank line on the end' => [ <<<'MARKDOWN' fsdfsdfsdf fsdfsdfsdf MARKDOWN, - )), - ); - self::assertEquals( - <<<'MARKDOWN' - fsdfsdfsdf - fsdfsdfsdf - MARKDOWN, - (string) (new Document( <<<'MARKDOWN' fsdfsdfsdf fsdfsdfsdf MARKDOWN, - )), - ); - self::assertEquals( - <<<'MARKDOWN' - fsdfsdfsdf - fsdfsdfsdf + null, + ], + 'Blank line on the end + Empty Mutation' => [ + <<<'MARKDOWN' + fsdfsdfsdf + fsdfsdfsdf - MARKDOWN, - (string) (new Document( + MARKDOWN, <<<'MARKDOWN' fsdfsdfsdf fsdfsdfsdf MARKDOWN, - )) - ->mutate(new Changeset([])), - ); - self::assertEquals( - <<<'MARKDOWN' - fsdfsdfsdf - fsdfsdfsdf + new Changeset([]), + ], + 'No blank line on the end + Empty Mutation' => [ + <<<'MARKDOWN' + fsdfsdfsdf + fsdfsdfsdf - MARKDOWN, - (string) (new Document( + MARKDOWN, <<<'MARKDOWN' fsdfsdfsdf fsdfsdfsdf MARKDOWN, - )) - ->mutate(new Changeset([])), - ); - self::assertEquals( - <<<'MARKDOWN' - fsdfsdfsdf - fsdfsdfsdf - fsdfsdfsdf + new Changeset([]), + ], + 'Blank line on the end + Append Mutation' => [ + <<<'MARKDOWN' + fsdfsdfsdf + fsdfsdfsdf + fsdfsdfsdf - MARKDOWN, - (string) (new Document( + MARKDOWN, <<<'MARKDOWN' fsdfsdfsdf fsdfsdfsdf MARKDOWN, - )) - ->mutate(new Changeset([[new Append(), 'fsdfsdfsdf']])), - ); - self::assertEquals( - <<<'MARKDOWN' - fsdfsdfsdf - fsdfsdfsdf - fsdfsdfsdf + new Changeset([[new Append(), 'fsdfsdfsdf']]), + ], + 'No blank line on the end + Append Mutation' => [ + <<<'MARKDOWN' + fsdfsdfsdf + fsdfsdfsdf + fsdfsdfsdf - MARKDOWN, - (string) (new Document( + MARKDOWN, <<<'MARKDOWN' fsdfsdfsdf fsdfsdfsdf MARKDOWN, - )) - ->mutate(new Changeset([[new Append(), 'fsdfsdfsdf']])), - ); + new Changeset([[new Append(), 'fsdfsdfsdf']]), + ], + ]; } + // } diff --git a/packages/documentator/src/Markdown/Markdown.php b/packages/documentator/src/Markdown/Markdown.php new file mode 100644 index 00000000..36696318 --- /dev/null +++ b/packages/documentator/src/Markdown/Markdown.php @@ -0,0 +1,35 @@ +environment = $this->initialize(); + $this->parser = new MarkdownParser($this->environment); + } + + protected function initialize(): Environment { + return (new GithubFlavoredMarkdownConverter())->getEnvironment() + ->addExtension(new Extension()); + } + + #[Override] + public function parse(string $content, ?FilePath $path = null): Document { + $node = $this->parser->parse($content); + $document = new Document($this, $node, $path); + + return $document; + } +} diff --git a/packages/documentator/src/Markdown/Mutations/CompositeTest.php b/packages/documentator/src/Markdown/Mutations/CompositeTest.php index f70d1c28..c8416c25 100644 --- a/packages/documentator/src/Markdown/Mutations/CompositeTest.php +++ b/packages/documentator/src/Markdown/Mutations/CompositeTest.php @@ -3,12 +3,10 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations; use LastDragon_ru\LaraASP\Documentator\Editor\Locations\Location; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Mutation; -use LastDragon_ru\LaraASP\Documentator\Markdown\Document; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; -use League\CommonMark\Node\Block\Document as DocumentNode; use Mockery; -use Override; use PHPUnit\Framework\Attributes\CoversClass; use function array_merge; @@ -19,12 +17,8 @@ #[CoversClass(Composite::class)] final class CompositeTest extends TestCase { public function testInvoke(): void { - $document = new class('') extends Document { - #[Override] - public function getNode(): DocumentNode { - return parent::getNode(); - } - }; + $markdown = $this->app()->make(Markdown::class); + $document = $markdown->parse(''); $aChanges = [ [new Location(1, 1, 10), 'a'], ]; diff --git a/packages/documentator/src/Markdown/Mutations/Document/MakeInlinableTest.php b/packages/documentator/src/Markdown/Mutations/Document/MakeInlinableTest.php index 8c4c115d..24abb8e5 100644 --- a/packages/documentator/src/Markdown/Mutations/Document/MakeInlinableTest.php +++ b/packages/documentator/src/Markdown/Mutations/Document/MakeInlinableTest.php @@ -3,23 +3,17 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Document; use LastDragon_ru\LaraASP\Core\Path\FilePath; -use LastDragon_ru\LaraASP\Documentator\Editor\Editor; -use LastDragon_ru\LaraASP\Documentator\Markdown\Document; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; -use League\CommonMark\Node\Block\Document as DocumentNode; -use Override; use PHPUnit\Framework\Attributes\CoversClass; -use function array_key_first; -use function array_values; - /** * @internal */ #[CoversClass(MakeInlinable::class)] final class MakeInlinableTest extends TestCase { public function testInvoke(): void { - $markdown = <<<'MARKDOWN' + $content = <<<'MARKDOWN' # Footnotes must be prefixed[^1] Text text text[^2] text text [^1] text text text [^2] text text text @@ -36,25 +30,10 @@ public function testInvoke(): void { [link]: https://example.com [image]: https://example.com MARKDOWN; - $document = new class($markdown, new FilePath(__FILE__)) extends Document { - #[Override] - public function getNode(): DocumentNode { - return parent::getNode(); - } - - /** - * @inheritDoc - */ - #[Override] - public function getLines(): array { - return parent::getLines(); - } - }; - $lines = $document->getLines(); - $offset = (int) array_key_first($lines); - $mutation = new MakeInlinable('prefix'); - $changes = $mutation($document); - $actual = (string) (new Editor(array_values($lines), $offset))->mutate($changes); + + $markdown = $this->app()->make(Markdown::class); + $document = $markdown->parse($content, new FilePath(__FILE__)); + $actual = (string) $document->mutate(new MakeInlinable('prefix')); self::assertEquals( <<<'MARKDOWN' @@ -73,6 +52,7 @@ public function getLines(): array { [prefix-link]: https://example.com [prefix-image]: https://example.com + MARKDOWN, $actual, ); diff --git a/packages/documentator/src/Markdown/Mutations/Document/MakeSplittableTest.php b/packages/documentator/src/Markdown/Mutations/Document/MakeSplittableTest.php index 65dac476..ed2c467b 100644 --- a/packages/documentator/src/Markdown/Mutations/Document/MakeSplittableTest.php +++ b/packages/documentator/src/Markdown/Mutations/Document/MakeSplittableTest.php @@ -3,23 +3,17 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Document; use LastDragon_ru\LaraASP\Core\Path\FilePath; -use LastDragon_ru\LaraASP\Documentator\Editor\Editor; -use LastDragon_ru\LaraASP\Documentator\Markdown\Document; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; -use League\CommonMark\Node\Block\Document as DocumentNode; -use Override; use PHPUnit\Framework\Attributes\CoversClass; -use function array_key_first; -use function array_values; - /** * @internal */ #[CoversClass(MakeSplittable::class)] final class MakeSplittableTest extends TestCase { public function testInvoke(): void { - $markdown = <<<'MARKDOWN' + $content = <<<'MARKDOWN' # Footnotes must be removed[^1] Text text text[^2] text text [^1] text text text [^2] text text text @@ -43,25 +37,10 @@ public function testInvoke(): void { [self]: #fragment MARKDOWN; - $document = new class($markdown, new FilePath(__FILE__)) extends Document { - #[Override] - public function getNode(): DocumentNode { - return parent::getNode(); - } - - /** - * @inheritDoc - */ - #[Override] - public function getLines(): array { - return parent::getLines(); - } - }; - $lines = $document->getLines(); - $offset = (int) array_key_first($lines); - $mutation = new MakeSplittable(); - $changes = $mutation($document); - $actual = (string) (new Editor(array_values($lines), $offset))->mutate($changes); + + $markdown = $this->app()->make(Markdown::class); + $document = $markdown->parse($content, new FilePath(__FILE__)); + $actual = (string) $document->mutate(new MakeSplittable()); self::assertEquals( <<<'MARKDOWN' diff --git a/packages/documentator/src/Markdown/Mutations/Document/Move.php b/packages/documentator/src/Markdown/Mutations/Document/Move.php index 50f66728..0cf4174b 100644 --- a/packages/documentator/src/Markdown/Mutations/Document/Move.php +++ b/packages/documentator/src/Markdown/Mutations/Document/Move.php @@ -52,10 +52,10 @@ public function __invoke(Document $document): iterable { yield from []; // No path? - $docPath = $document->getPath(); + $docPath = $document->path; if ($docPath === null) { - $document->setPath($this->path->getNormalizedPath()); + $document->path = $this->path->getNormalizedPath(); return; } @@ -120,7 +120,7 @@ public function __invoke(Document $document): iterable { } // Set - $document->setPath($newPath); + $document->path = $newPath; } /** @@ -131,7 +131,7 @@ private function nodes(Document $document): Iterator { yield from []; // Search - foreach ($document->getNode()->iterator() as $node) { + foreach ($document->node->iterator() as $node) { $url = null; if ($node instanceof AbstractWebResource && Reference::get($node) === null) { diff --git a/packages/documentator/src/Markdown/Mutations/Document/MoveTest.php b/packages/documentator/src/Markdown/Mutations/Document/MoveTest.php index bbd8a14a..de19e387 100644 --- a/packages/documentator/src/Markdown/Mutations/Document/MoveTest.php +++ b/packages/documentator/src/Markdown/Mutations/Document/MoveTest.php @@ -3,17 +3,11 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Document; use LastDragon_ru\LaraASP\Core\Path\FilePath; -use LastDragon_ru\LaraASP\Documentator\Editor\Editor; -use LastDragon_ru\LaraASP\Documentator\Markdown\Document; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; -use League\CommonMark\Node\Block\Document as DocumentNode; -use Override; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; -use function array_key_first; -use function array_values; - /** * @internal */ @@ -24,25 +18,9 @@ final class MoveTest extends TestCase { #[DataProvider('dataProviderInvoke')] public function testInvoke(string $expected, ?string $path, string $content, string $target): void { $path = $path !== null ? new FilePath($path) : null; - $mutation = new Move(new FilePath($target)); - $document = new class($content, $path) extends Document { - #[Override] - public function getNode(): DocumentNode { - return parent::getNode(); - } - - /** - * @inheritDoc - */ - #[Override] - public function getLines(): array { - return parent::getLines(); - } - }; - $lines = $document->getLines(); - $offset = (int) array_key_first($lines); - $changes = $mutation($document); - $actual = (string) (new Editor(array_values($lines), $offset))->mutate($changes); + $markdown = $this->app()->make(Markdown::class); + $document = $markdown->parse($content, $path); + $actual = (string) $document->mutate(new Move(new FilePath($target))); self::assertEquals($expected, $actual); } @@ -59,6 +37,7 @@ public static function dataProviderInvoke(): array { 'from `null`' => [ <<<'MARKDOWN' [foo]: relative/path/from "title" + MARKDOWN, null, <<<'MARKDOWN' @@ -69,6 +48,7 @@ public static function dataProviderInvoke(): array { 'same' => [ <<<'MARKDOWN' [foo]: /path "title" + MARKDOWN, '/path/file.md', <<<'MARKDOWN' @@ -79,6 +59,7 @@ public static function dataProviderInvoke(): array { 'empty' => [ <<<'MARKDOWN' [foo]: # "title" + MARKDOWN, '/path/from/file.md', <<<'MARKDOWN' @@ -90,6 +71,7 @@ public static function dataProviderInvoke(): array { <<<'MARKDOWN' [foo]: ../from/path?a=123#fragment [bar]: ?a=123#fragment + MARKDOWN, '/path/from/file.md', <<<'MARKDOWN' @@ -143,6 +125,7 @@ public static function dataProviderInvoke(): array { > [quote]: ../file/a > > [quote]: ../from/file/b (title) + MARKDOWN, '/path/from/file.md', <<<'MARKDOWN' @@ -229,6 +212,7 @@ public static function dataProviderInvoke(): array { |-------------------------|-----------------------------------------------------------------| | Cell [link][link] cell. | Cell `\|` \\| [table](<../from/file\|a> "\|") | | Cell | Cell cell [table](https://example.com/) cell [table](../from/file/a). | + MARKDOWN, '/path/from/file.md', <<<'MARKDOWN' @@ -301,6 +285,7 @@ public static function dataProviderInvoke(): array { |-------------------------|-------------------------------------------------------------------| | Cell [link][link] cell. | Cell `\|` \\| ![table](<../from/file\|a> "\|") | | Cell | Cell cell ![table](https://example.com/) cell ![table](../from/file/a). | + MARKDOWN, '/path/from/file.md', <<<'MARKDOWN' @@ -359,6 +344,7 @@ public static function dataProviderInvoke(): array { [^note]: Text text [tel](tel:+70000000000 "title") text [link](../from/file/a) text [absolute](/path/to/file 'title') text [link](../from/file/b) + MARKDOWN, '/path/from/file.md', <<<'MARKDOWN' diff --git a/packages/documentator/src/Markdown/Mutations/Footnote/Prefix.php b/packages/documentator/src/Markdown/Mutations/Footnote/Prefix.php index b41d039c..7114a217 100644 --- a/packages/documentator/src/Markdown/Mutations/Footnote/Prefix.php +++ b/packages/documentator/src/Markdown/Mutations/Footnote/Prefix.php @@ -32,7 +32,7 @@ public function __invoke(Document $document): iterable { yield from []; // Process - foreach ($document->getNode()->iterator() as $node) { + foreach ($document->node->iterator() as $node) { // Footnote? if (!($node instanceof FootnoteRef) && !($node instanceof Footnote)) { continue; diff --git a/packages/documentator/src/Markdown/Mutations/Footnote/PrefixTest.php b/packages/documentator/src/Markdown/Mutations/Footnote/PrefixTest.php index c05bc523..176090d9 100644 --- a/packages/documentator/src/Markdown/Mutations/Footnote/PrefixTest.php +++ b/packages/documentator/src/Markdown/Mutations/Footnote/PrefixTest.php @@ -3,23 +3,17 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Footnote; use LastDragon_ru\LaraASP\Core\Path\FilePath; -use LastDragon_ru\LaraASP\Documentator\Editor\Editor; -use LastDragon_ru\LaraASP\Documentator\Markdown\Document; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; -use League\CommonMark\Node\Block\Document as DocumentNode; -use Override; use PHPUnit\Framework\Attributes\CoversClass; -use function array_key_first; -use function array_values; - /** * @internal */ #[CoversClass(Prefix::class)] final class PrefixTest extends TestCase { public function testInvoke(): void { - $markdown = <<<'MARKDOWN' + $content = <<<'MARKDOWN' # Header[^1] Text text text[^2] text text [^1] text text text [^2] text text text @@ -41,25 +35,10 @@ public function testInvoke(): void { text text text text text text text text text text text text text text. MARKDOWN; - $document = new class($markdown, new FilePath(__FILE__)) extends Document { - #[Override] - public function getNode(): DocumentNode { - return parent::getNode(); - } - - /** - * @inheritDoc - */ - #[Override] - public function getLines(): array { - return parent::getLines(); - } - }; - $lines = $document->getLines(); - $offset = (int) array_key_first($lines); - $mutation = new Prefix('prefix'); - $changes = $mutation($document); - $actual = (string) (new Editor(array_values($lines), $offset))->mutate($changes); + + $markdown = $this->app()->make(Markdown::class); + $document = $markdown->parse($content, new FilePath(__FILE__)); + $actual = (string) $document->mutate(new Prefix('prefix')); self::assertEquals( <<<'MARKDOWN' @@ -83,6 +62,7 @@ public function getLines(): array { Text text text text text text text text text text text text text text text text text text text text text text text text text text text. + MARKDOWN, $actual, ); diff --git a/packages/documentator/src/Markdown/Mutations/Footnote/Remove.php b/packages/documentator/src/Markdown/Mutations/Footnote/Remove.php index cfd3fe61..61c73052 100644 --- a/packages/documentator/src/Markdown/Mutations/Footnote/Remove.php +++ b/packages/documentator/src/Markdown/Mutations/Footnote/Remove.php @@ -27,7 +27,7 @@ public function __invoke(Document $document): iterable { yield from []; // Process - foreach ($document->getNode()->iterator() as $node) { + foreach ($document->node->iterator() as $node) { $location = match (true) { $node instanceof FootnoteRef, $node instanceof Footnote => LocationData::get($node), default => null, diff --git a/packages/documentator/src/Markdown/Mutations/Footnote/RemoveTest.php b/packages/documentator/src/Markdown/Mutations/Footnote/RemoveTest.php index 2d6173d8..1e5cffaa 100644 --- a/packages/documentator/src/Markdown/Mutations/Footnote/RemoveTest.php +++ b/packages/documentator/src/Markdown/Mutations/Footnote/RemoveTest.php @@ -2,23 +2,17 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Footnote; -use LastDragon_ru\LaraASP\Documentator\Editor\Editor; -use LastDragon_ru\LaraASP\Documentator\Markdown\Document; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; -use League\CommonMark\Node\Block\Document as DocumentNode; -use Override; use PHPUnit\Framework\Attributes\CoversClass; -use function array_key_first; -use function array_values; - /** * @internal */ #[CoversClass(Remove::class)] final class RemoveTest extends TestCase { public function testInvoke(): void { - $markdown = <<<'MARKDOWN' + $content = <<<'MARKDOWN' # Header[^1] Text text text[^2] text text [^1] text text text [^2] text text text @@ -40,25 +34,10 @@ public function testInvoke(): void { text text text text text text text text text text text text text text. MARKDOWN; - $document = new class($markdown) extends Document { - #[Override] - public function getNode(): DocumentNode { - return parent::getNode(); - } - - /** - * @inheritDoc - */ - #[Override] - public function getLines(): array { - return parent::getLines(); - } - }; - $lines = $document->getLines(); - $offset = (int) array_key_first($lines); - $mutation = new Remove(); - $changes = $mutation($document); - $actual = (string) (new Editor(array_values($lines), $offset))->mutate($changes); + + $markdown = $this->app()->make(Markdown::class); + $document = $markdown->parse($content); + $actual = (string) $document->mutate(new Remove()); self::assertEquals( <<<'MARKDOWN' diff --git a/packages/documentator/src/Markdown/Mutations/Generated/Unwrap.php b/packages/documentator/src/Markdown/Mutations/Generated/Unwrap.php index 1da7fa50..52ce6373 100644 --- a/packages/documentator/src/Markdown/Mutations/Generated/Unwrap.php +++ b/packages/documentator/src/Markdown/Mutations/Generated/Unwrap.php @@ -27,7 +27,7 @@ public function __invoke(Document $document): iterable { yield from []; // Process - foreach ($document->getNode()->iterator(NodeIterator::FLAG_BLOCKS_ONLY) as $node) { + foreach ($document->node->iterator(NodeIterator::FLAG_BLOCKS_ONLY) as $node) { // Generated? if (!($node instanceof Block)) { continue; diff --git a/packages/documentator/src/Markdown/Mutations/Generated/UnwrapTest.php b/packages/documentator/src/Markdown/Mutations/Generated/UnwrapTest.php index aa8e549e..2fe8af5c 100644 --- a/packages/documentator/src/Markdown/Mutations/Generated/UnwrapTest.php +++ b/packages/documentator/src/Markdown/Mutations/Generated/UnwrapTest.php @@ -2,23 +2,17 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Generated; -use LastDragon_ru\LaraASP\Documentator\Editor\Editor; -use LastDragon_ru\LaraASP\Documentator\Markdown\Document; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; -use League\CommonMark\Node\Block\Document as DocumentNode; -use Override; use PHPUnit\Framework\Attributes\CoversClass; -use function array_key_first; -use function array_values; - /** * @internal */ #[CoversClass(Unwrap::class)] final class UnwrapTest extends TestCase { public function testInvoke(): void { - $markdown = <<<'MARKDOWN' + $content = <<<'MARKDOWN' # Header [//]: # (start: block) @@ -54,25 +48,10 @@ public function testInvoke(): void { Up to the end. MARKDOWN; - $document = new class($markdown) extends Document { - #[Override] - public function getNode(): DocumentNode { - return parent::getNode(); - } - - /** - * @inheritDoc - */ - #[Override] - public function getLines(): array { - return parent::getLines(); - } - }; - $lines = $document->getLines(); - $offset = (int) array_key_first($lines); - $mutation = new Unwrap(); - $changes = $mutation($document); - $actual = (string) (new Editor(array_values($lines), $offset))->mutate($changes); + + $markdown = $this->app()->make(Markdown::class); + $document = $markdown->parse($content); + $actual = (string) $document->mutate(new Unwrap()); self::assertEquals( <<<'MARKDOWN' @@ -97,6 +76,7 @@ public function getLines(): array { > [//]: # (end: nested) Up to the end. + MARKDOWN, $actual, ); diff --git a/packages/documentator/src/Markdown/Mutations/Heading/Renumber.php b/packages/documentator/src/Markdown/Mutations/Heading/Renumber.php index 7ffdff1e..1445a88a 100644 --- a/packages/documentator/src/Markdown/Mutations/Heading/Renumber.php +++ b/packages/documentator/src/Markdown/Mutations/Heading/Renumber.php @@ -64,7 +64,7 @@ public function __invoke(Document $document): iterable { private function getHeadings(Document $document, int &$highest): array { $headings = []; - foreach ($document->getNode()->iterator() as $node) { + foreach ($document->node->iterator() as $node) { // Heading? if (!($node instanceof Heading)) { continue; diff --git a/packages/documentator/src/Markdown/Mutations/Heading/RenumberTest.php b/packages/documentator/src/Markdown/Mutations/Heading/RenumberTest.php index c695c926..3913deed 100644 --- a/packages/documentator/src/Markdown/Mutations/Heading/RenumberTest.php +++ b/packages/documentator/src/Markdown/Mutations/Heading/RenumberTest.php @@ -2,17 +2,11 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Heading; -use LastDragon_ru\LaraASP\Documentator\Editor\Editor; -use LastDragon_ru\LaraASP\Documentator\Markdown\Document; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; -use League\CommonMark\Node\Block\Document as DocumentNode; -use Override; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; -use function array_key_first; -use function array_values; - /** * @internal */ @@ -24,25 +18,10 @@ final class RenumberTest extends TestCase { * @param int<1, 6> $level */ #[DataProvider('dataProviderInvoke')] - public function testInvoke(string $expected, int $level, string $markdown): void { - $document = new class($markdown) extends Document { - #[Override] - public function getNode(): DocumentNode { - return parent::getNode(); - } - - /** - * @inheritDoc - */ - #[Override] - public function getLines(): array { - return parent::getLines(); - } - }; - $lines = $document->getLines(); - $offset = (int) array_key_first($lines); - $editor = new Editor(array_values($lines), $offset); - $actual = (string) $editor->mutate((new Renumber($level))($document)); + public function testInvoke(string $expected, int $level, string $content): void { + $markdown = $this->app()->make(Markdown::class); + $document = $markdown->parse($content); + $actual = (string) $document->mutate(new Renumber($level)); self::assertEquals($expected, $actual); } @@ -60,6 +39,7 @@ public static function dataProviderInvoke(): array { ## A ### B ### + MARKDOWN, 2, <<<'MARKDOWN' @@ -106,6 +86,7 @@ public static function dataProviderInvoke(): array { ### Header 2 * item + MARKDOWN, 2, <<<'MARKDOWN' @@ -176,6 +157,7 @@ public static function dataProviderInvoke(): array { Foo *bar* --------- + MARKDOWN, 1, <<<'MARKDOWN' diff --git a/packages/documentator/src/Markdown/Mutations/Link/Remove.php b/packages/documentator/src/Markdown/Mutations/Link/Remove.php index cd989d5f..c1cd91da 100644 --- a/packages/documentator/src/Markdown/Mutations/Link/Remove.php +++ b/packages/documentator/src/Markdown/Mutations/Link/Remove.php @@ -47,7 +47,7 @@ private function nodes(Document $document): Iterator { yield from []; // Search - foreach ($document->getNode()->iterator() as $node) { + foreach ($document->node->iterator() as $node) { if ($node instanceof Link && $this->isLink($document, $node)) { yield $node; } diff --git a/packages/documentator/src/Markdown/Mutations/Link/RemoveTest.php b/packages/documentator/src/Markdown/Mutations/Link/RemoveTest.php index bd34720f..1111c03c 100644 --- a/packages/documentator/src/Markdown/Mutations/Link/RemoveTest.php +++ b/packages/documentator/src/Markdown/Mutations/Link/RemoveTest.php @@ -3,23 +3,17 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Link; use LastDragon_ru\LaraASP\Core\Path\FilePath; -use LastDragon_ru\LaraASP\Documentator\Editor\Editor; -use LastDragon_ru\LaraASP\Documentator\Markdown\Document; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; -use League\CommonMark\Node\Block\Document as DocumentNode; -use Override; use PHPUnit\Framework\Attributes\CoversClass; -use function array_key_first; -use function array_values; - /** * @internal */ #[CoversClass(Remove::class)] final class RemoveTest extends TestCase { public function testInvoke(): void { - $markdown = <<<'MARKDOWN' + $content = <<<'MARKDOWN' # Header Text text [link](https://example.com) text text [`link`][link] text @@ -43,25 +37,10 @@ public function testInvoke(): void { | Cell [link][self] cell. | Cell `\|` \\| ![table][image] | | Cell | Cell cell [table][self]. | MARKDOWN; - $document = new class($markdown, new FilePath('path/to/file.md')) extends Document { - #[Override] - public function getNode(): DocumentNode { - return parent::getNode(); - } - - /** - * @inheritDoc - */ - #[Override] - public function getLines(): array { - return parent::getLines(); - } - }; - $lines = $document->getLines(); - $offset = (int) array_key_first($lines); - $mutation = new Remove(); - $changes = $mutation($document); - $actual = (string) (new Editor(array_values($lines), $offset))->mutate($changes); + + $markdown = $this->app()->make(Markdown::class); + $document = $markdown->parse($content, new FilePath('path/to/file.md')); + $actual = (string) $document->mutate(new Remove()); self::assertEquals( <<<'MARKDOWN' @@ -87,6 +66,7 @@ public function getLines(): array { |-------------------------|-------------------------------| | Cell link cell. | Cell `\|` \\| ![table][image] | | Cell | Cell cell table. | + MARKDOWN, $actual, ); diff --git a/packages/documentator/src/Markdown/Mutations/Link/RemoveToSelfTest.php b/packages/documentator/src/Markdown/Mutations/Link/RemoveToSelfTest.php index d32440e6..694d1428 100644 --- a/packages/documentator/src/Markdown/Mutations/Link/RemoveToSelfTest.php +++ b/packages/documentator/src/Markdown/Mutations/Link/RemoveToSelfTest.php @@ -3,23 +3,17 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Link; use LastDragon_ru\LaraASP\Core\Path\FilePath; -use LastDragon_ru\LaraASP\Documentator\Editor\Editor; -use LastDragon_ru\LaraASP\Documentator\Markdown\Document; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; -use League\CommonMark\Node\Block\Document as DocumentNode; -use Override; use PHPUnit\Framework\Attributes\CoversClass; -use function array_key_first; -use function array_values; - /** * @internal */ #[CoversClass(RemoveToSelf::class)] final class RemoveToSelfTest extends TestCase { public function testInvoke(): void { - $markdown = <<<'MARKDOWN' + $content = <<<'MARKDOWN' # Header Text text [link](https://example.com) text text [`link`][link] text @@ -53,25 +47,10 @@ public function testInvoke(): void { | Cell [link][self-a] cell. | Cell `\|` \\| ![table][image] | | Cell | Cell cell [table][self-a]. | MARKDOWN; - $document = new class($markdown, new FilePath('path/to/file.md')) extends Document { - #[Override] - public function getNode(): DocumentNode { - return parent::getNode(); - } - - /** - * @inheritDoc - */ - #[Override] - public function getLines(): array { - return parent::getLines(); - } - }; - $lines = $document->getLines(); - $offset = (int) array_key_first($lines); - $mutation = new RemoveToSelf(); - $changes = $mutation($document); - $actual = (string) (new Editor(array_values($lines), $offset))->mutate($changes); + + $markdown = $this->app()->make(Markdown::class); + $document = $markdown->parse($content, new FilePath('path/to/file.md')); + $actual = (string) $document->mutate(new RemoveToSelf()); self::assertEquals( <<<'MARKDOWN' @@ -107,6 +86,7 @@ public function getLines(): array { |---------------------------|-------------------------------| | Cell link cell. | Cell `\|` \\| ![table][image] | | Cell | Cell cell table. | + MARKDOWN, $actual, ); diff --git a/packages/documentator/src/Markdown/Mutations/Reference/Inline.php b/packages/documentator/src/Markdown/Mutations/Reference/Inline.php index 9a36574c..9cf912e6 100644 --- a/packages/documentator/src/Markdown/Mutations/Reference/Inline.php +++ b/packages/documentator/src/Markdown/Mutations/Reference/Inline.php @@ -65,7 +65,7 @@ private function nodes(Document $document): Iterator { yield from []; // Search - foreach ($document->getNode()->iterator() as $node) { + foreach ($document->node->iterator() as $node) { if ($node instanceof AbstractWebResource && Reference::get($node) !== null) { yield $node; } elseif ($node instanceof ReferenceNode) { diff --git a/packages/documentator/src/Markdown/Mutations/Reference/InlineTest.php b/packages/documentator/src/Markdown/Mutations/Reference/InlineTest.php index af8f35b9..50937b0d 100644 --- a/packages/documentator/src/Markdown/Mutations/Reference/InlineTest.php +++ b/packages/documentator/src/Markdown/Mutations/Reference/InlineTest.php @@ -2,23 +2,17 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Reference; -use LastDragon_ru\LaraASP\Documentator\Editor\Editor; -use LastDragon_ru\LaraASP\Documentator\Markdown\Document; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; -use League\CommonMark\Node\Block\Document as DocumentNode; -use Override; use PHPUnit\Framework\Attributes\CoversClass; -use function array_key_first; -use function array_values; - /** * @internal */ #[CoversClass(Inline::class)] final class InlineTest extends TestCase { public function testInvoke(): void { - $markdown = <<<'MARKDOWN' + $content = <<<'MARKDOWN' # Header Text text [link](https://example.com) text text [`link`][link] text @@ -43,25 +37,10 @@ public function testInvoke(): void { | Cell [link][link] cell. | Cell `\|` \\| ![table][table] | | Cell | Cell cell ![table][link]. | MARKDOWN; - $document = new class($markdown) extends Document { - #[Override] - public function getNode(): DocumentNode { - return parent::getNode(); - } - - /** - * @inheritDoc - */ - #[Override] - public function getLines(): array { - return parent::getLines(); - } - }; - $lines = $document->getLines(); - $offset = (int) array_key_first($lines); - $mutation = new Inline(); - $changes = $mutation($document); - $actual = (string) (new Editor(array_values($lines), $offset))->mutate($changes); + + $markdown = $this->app()->make(Markdown::class); + $document = $markdown->parse($content); + $actual = (string) $document->mutate(new Inline()); self::assertEquals( <<<'MARKDOWN' @@ -84,6 +63,7 @@ public function getLines(): array { |-------------------------|-------------------------------| | Cell [link](https://example.com) cell. | Cell `\|` \\| ![table](https://example.com "table \| cell") | | Cell | Cell cell ![table](https://example.com). | + MARKDOWN, $actual, ); diff --git a/packages/documentator/src/Markdown/Mutations/Reference/Prefix.php b/packages/documentator/src/Markdown/Mutations/Reference/Prefix.php index 58640455..6232e17f 100644 --- a/packages/documentator/src/Markdown/Mutations/Reference/Prefix.php +++ b/packages/documentator/src/Markdown/Mutations/Reference/Prefix.php @@ -83,7 +83,7 @@ private function nodes(Document $document): Iterator { yield from []; // Search - foreach ($document->getNode()->iterator() as $node) { + foreach ($document->node->iterator() as $node) { if ($node instanceof AbstractWebResource && ReferenceData::get($node) !== null) { yield $node; } elseif ($node instanceof ReferenceNode) { diff --git a/packages/documentator/src/Markdown/Mutations/Reference/PrefixTest.php b/packages/documentator/src/Markdown/Mutations/Reference/PrefixTest.php index 471b8e3b..ff459e42 100644 --- a/packages/documentator/src/Markdown/Mutations/Reference/PrefixTest.php +++ b/packages/documentator/src/Markdown/Mutations/Reference/PrefixTest.php @@ -3,23 +3,17 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Reference; use LastDragon_ru\LaraASP\Core\Path\FilePath; -use LastDragon_ru\LaraASP\Documentator\Editor\Editor; -use LastDragon_ru\LaraASP\Documentator\Markdown\Document; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; -use League\CommonMark\Node\Block\Document as DocumentNode; -use Override; use PHPUnit\Framework\Attributes\CoversClass; -use function array_key_first; -use function array_values; - /** * @internal */ #[CoversClass(Prefix::class)] final class PrefixTest extends TestCase { public function testInvoke(): void { - $markdown = <<<'MARKDOWN' + $content = <<<'MARKDOWN' # Header Text text [link](https://example.com) text text [`link`][link] text @@ -43,25 +37,10 @@ public function testInvoke(): void { | Cell [link][link] cell. | Cell `\|` \\| ![table][image] | | Cell | Cell cell [table][link]. | MARKDOWN; - $document = new class($markdown, new FilePath('path/to/file.md')) extends Document { - #[Override] - public function getNode(): DocumentNode { - return parent::getNode(); - } - - /** - * @inheritDoc - */ - #[Override] - public function getLines(): array { - return parent::getLines(); - } - }; - $lines = $document->getLines(); - $offset = (int) array_key_first($lines); - $mutation = new Prefix('prefix'); - $changes = $mutation($document); - $actual = (string) (new Editor(array_values($lines), $offset))->mutate($changes); + + $markdown = $this->app()->make(Markdown::class); + $document = $markdown->parse($content, new FilePath('path/to/file.md')); + $actual = (string) $document->mutate(new Prefix('prefix')); self::assertEquals( <<<'MARKDOWN' @@ -87,6 +66,7 @@ public function getLines(): array { |-------------------------|-------------------------------| | Cell [link][prefix-link] cell. | Cell `\|` \\| ![table][prefix-image] | | Cell | Cell cell [table][prefix-link]. | + MARKDOWN, $actual, ); diff --git a/packages/documentator/src/Markdown/Utils.php b/packages/documentator/src/Markdown/Utils.php index 9f13273d..68d60fc1 100644 --- a/packages/documentator/src/Markdown/Utils.php +++ b/packages/documentator/src/Markdown/Utils.php @@ -205,7 +205,7 @@ public static function isPathRelative(string $path): bool { } public static function isPathToSelf(Document $document, FilePath|string $path): bool { - $self = $document->getPath(); + $self = $document->path; $path = (string) parse_url((string) $path, PHP_URL_PATH); $is = $path === '' || $path === '.' || $self === null || $self->isEqual($self->getFilePath($path)); diff --git a/packages/documentator/src/Markdown/UtilsTest.php b/packages/documentator/src/Markdown/UtilsTest.php index 9f52ad3b..ba7bf393 100644 --- a/packages/documentator/src/Markdown/UtilsTest.php +++ b/packages/documentator/src/Markdown/UtilsTest.php @@ -3,6 +3,7 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown; use LastDragon_ru\LaraASP\Core\Path\FilePath; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; use PHPUnit\Framework\Attributes\CoversClass; @@ -30,8 +31,9 @@ public function testIsPathRelative(): void { } public function testIsPathToSelf(): void { - $a = new Document('', new FilePath('/path/to/a.md')); - $b = new Document('', new FilePath('/path/to/b.md')); + $md = $this->app()->make(Markdown::class); + $a = $md->parse('', new FilePath('/path/to/a.md')); + $b = $md->parse('', new FilePath('/path/to/b.md')); self::assertTrue(Utils::isPathToSelf($a, '.')); self::assertTrue(Utils::isPathToSelf($a, '#fragment')); diff --git a/packages/documentator/src/PackageProvider.php b/packages/documentator/src/PackageProvider.php index a4559609..a92789eb 100644 --- a/packages/documentator/src/PackageProvider.php +++ b/packages/documentator/src/PackageProvider.php @@ -7,6 +7,8 @@ use LastDragon_ru\LaraASP\Documentator\Commands\Commands; use LastDragon_ru\LaraASP\Documentator\Commands\Preprocess; use LastDragon_ru\LaraASP\Documentator\Commands\Requirements; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown as MarkdownContract; +use LastDragon_ru\LaraASP\Documentator\Markdown\Markdown; use LastDragon_ru\LaraASP\Documentator\Processor\Contracts\Factory as ProcessorFactoryContract; use LastDragon_ru\LaraASP\Documentator\Processor\Factory as ProcessorFactory; use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\CodeLinks\Contracts\LinkFactory as LinkFactoryContract; @@ -22,6 +24,7 @@ public function register(): void { $this->app->scopedIf(ProcessorFactoryContract::class, ProcessorFactory::class); $this->app->scopedIf(LinkFactoryContract::class, LinkFactory::class); + $this->app->scopedIf(MarkdownContract::class, Markdown::class); } public function boot(): void { diff --git a/packages/documentator/src/Processor/Metadata/Markdown.php b/packages/documentator/src/Processor/Metadata/Markdown.php index 2e685f15..21088ed7 100644 --- a/packages/documentator/src/Processor/Metadata/Markdown.php +++ b/packages/documentator/src/Processor/Metadata/Markdown.php @@ -2,6 +2,7 @@ namespace LastDragon_ru\LaraASP\Documentator\Processor\Metadata; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown as MarkdownContract; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; use LastDragon_ru\LaraASP\Documentator\Processor\Contracts\Metadata; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File; @@ -11,14 +12,16 @@ * @implements Metadata */ class Markdown implements Metadata { - public function __construct() { + public function __construct( + protected readonly MarkdownContract $markdown, + ) { // empty } #[Override] public function __invoke(File $file): mixed { return $file->getExtension() === 'md' - ? new Document($file->getContent(), $file->getPath()) + ? $this->markdown->parse($file->getContent(), $file->getPath()) : null; } } diff --git a/packages/documentator/src/Processor/Metadata/PhpClassMarkdown.php b/packages/documentator/src/Processor/Metadata/PhpClassMarkdown.php index 0df2aac5..845f882b 100644 --- a/packages/documentator/src/Processor/Metadata/PhpClassMarkdown.php +++ b/packages/documentator/src/Processor/Metadata/PhpClassMarkdown.php @@ -5,7 +5,7 @@ use LastDragon_ru\LaraASP\Documentator\Markdown\Document; use LastDragon_ru\LaraASP\Documentator\Processor\Contracts\Metadata; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File; -use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\CodeLinks\Contracts\LinkFactory; +use LastDragon_ru\LaraASP\Documentator\Utils\PhpDocumentFactory; use Override; /** @@ -13,7 +13,7 @@ */ class PhpClassMarkdown implements Metadata { public function __construct( - protected readonly LinkFactory $factory, + protected readonly PhpDocumentFactory $factory, protected readonly PhpClassComment $comment, ) { // empty @@ -32,7 +32,7 @@ public function __invoke(File $file): mixed { } // Parse - $document = $comment->comment->getDocument($this->factory, $comment->context, $file->getPath()); + $document = ($this->factory)($comment->comment, $file->getPath(), $comment->context); return $document; } diff --git a/packages/documentator/src/Processor/Metadata/PhpClassMarkdownTest.php b/packages/documentator/src/Processor/Metadata/PhpClassMarkdownTest.php index df3acb74..ba958fcf 100644 --- a/packages/documentator/src/Processor/Metadata/PhpClassMarkdownTest.php +++ b/packages/documentator/src/Processor/Metadata/PhpClassMarkdownTest.php @@ -4,8 +4,8 @@ use LastDragon_ru\LaraASP\Core\Path\FilePath; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File; -use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\CodeLinks\Contracts\LinkFactory; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; +use LastDragon_ru\LaraASP\Documentator\Utils\PhpDocumentFactory; use Override; use PHPUnit\Framework\Attributes\CoversClass; @@ -37,7 +37,7 @@ class A { false, ); $factory = new PhpClassMarkdown( - $this->app()->make(LinkFactory::class), + $this->app()->make(PhpDocumentFactory::class), new PhpClassComment(new PhpClass()), ); $metadata = $factory($file); @@ -48,6 +48,7 @@ class A { Description. Summary `\stdClass` and `\LastDragon_ru\LaraASP\Documentator\Processor\Metadata\PhpClass`, {@see https://example.com/}. + MARKDOWN, (string) $metadata, ); @@ -55,7 +56,10 @@ class A { public function testInvokeEmpty(): void { $file = new File((new FilePath(__FILE__))->getNormalizedPath(), false); - $factory = new PhpClassMarkdown($this->app()->make(LinkFactory::class), new PhpClassComment(new PhpClass())); + $factory = new PhpClassMarkdown( + $this->app()->make(PhpDocumentFactory::class), + new PhpClassComment(new PhpClass()), + ); $metadata = $factory($file); self::assertNotNull($metadata); @@ -65,7 +69,7 @@ public function testInvokeEmpty(): void { public function testInvokeNotPhp(): void { $file = new File((new FilePath(__FILE__))->getNormalizedPath(), false); $factory = new PhpClassMarkdown( - $this->app()->make(LinkFactory::class), + $this->app()->make(PhpDocumentFactory::class), new class(new PhpClass()) extends PhpClassComment { #[Override] public function __invoke(File $file): mixed { diff --git a/packages/documentator/src/Processor/Metadata/PhpDocBlock.php b/packages/documentator/src/Processor/Metadata/PhpDocBlock.php index 29e645a6..47b188af 100644 --- a/packages/documentator/src/Processor/Metadata/PhpDocBlock.php +++ b/packages/documentator/src/Processor/Metadata/PhpDocBlock.php @@ -2,6 +2,7 @@ namespace LastDragon_ru\LaraASP\Documentator\Processor\Metadata; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; use LastDragon_ru\LaraASP\Documentator\Package; use LastDragon_ru\LaraASP\Documentator\Processor\Contracts\Metadata; @@ -29,6 +30,7 @@ */ class PhpDocBlock implements Metadata { public function __construct( + protected readonly Markdown $markdown, protected readonly LinkFactory $factory, protected readonly PhpClass $class, ) { @@ -53,7 +55,7 @@ public function __invoke(File $file): mixed { $content = trim($content); // Create - return new Document($content, $file->getPath()); + return $this->markdown->parse($content, $file->getPath()); } private function preprocess(NameContext $context, string $string): string { diff --git a/packages/documentator/src/Processor/Metadata/PhpDocBlockTest.php b/packages/documentator/src/Processor/Metadata/PhpDocBlockTest.php index 56c171a1..69c58c91 100644 --- a/packages/documentator/src/Processor/Metadata/PhpDocBlockTest.php +++ b/packages/documentator/src/Processor/Metadata/PhpDocBlockTest.php @@ -3,6 +3,7 @@ namespace LastDragon_ru\LaraASP\Documentator\Processor\Metadata; use LastDragon_ru\LaraASP\Core\Path\FilePath; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File; use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\CodeLinks\Contracts\LinkFactory; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; @@ -38,6 +39,7 @@ class A { false, ); $factory = new PhpDocBlock( + $this->app()->make(Markdown::class), $this->app()->make(LinkFactory::class), new PhpClass(), ); @@ -49,6 +51,7 @@ class A { Description. Summary `\stdClass` and `\LastDragon_ru\LaraASP\Documentator\Processor\Metadata\PhpClass`, {@see https://example.com/}. + MARKDOWN, (string) $metadata, ); @@ -56,7 +59,11 @@ class A { public function testInvokeEmpty(): void { $file = new File((new FilePath(__FILE__))->getNormalizedPath(), false); - $factory = new PhpDocBlock($this->app()->make(LinkFactory::class), new PhpClass()); + $factory = new PhpDocBlock( + $this->app()->make(Markdown::class), + $this->app()->make(LinkFactory::class), + new PhpClass(), + ); $metadata = $factory($file); self::assertNotNull($metadata); @@ -66,6 +73,7 @@ public function testInvokeEmpty(): void { public function testInvokeNotPhp(): void { $file = new File((new FilePath(__FILE__))->getNormalizedPath(), false); $factory = new PhpDocBlock( + $this->app()->make(Markdown::class), $this->app()->make(LinkFactory::class), new class() extends PhpClass { #[Override] diff --git a/packages/documentator/src/Processor/Tasks/CodeLinks/Task.php b/packages/documentator/src/Processor/Tasks/CodeLinks/Task.php index 1fac08d4..f3a60309 100644 --- a/packages/documentator/src/Processor/Tasks/CodeLinks/Task.php +++ b/packages/documentator/src/Processor/Tasks/CodeLinks/Task.php @@ -179,7 +179,7 @@ private function getChanges(Document $document, array $blocks, array $links): ar $changes = []; // Remove blocks - $refsParentNode = $document->getNode(); + $refsParentNode = $document->node; $refsParentLocation = null; foreach ($blocks as $block) { @@ -285,7 +285,7 @@ protected function parse(Document $document): array { $links = []; $blocks = []; - foreach ($document->getNode()->iterator() as $node) { + foreach ($document->node->iterator() as $node) { if ($node instanceof GeneratedNode && $node->id === static::BlockMarker) { $blocks[] = $node; } elseif ($node instanceof CodeNode) { diff --git a/packages/documentator/src/Processor/Tasks/CodeLinks/TaskTest.php b/packages/documentator/src/Processor/Tasks/CodeLinks/TaskTest.php index 8fc59f40..04348254 100644 --- a/packages/documentator/src/Processor/Tasks/CodeLinks/TaskTest.php +++ b/packages/documentator/src/Processor/Tasks/CodeLinks/TaskTest.php @@ -5,6 +5,7 @@ use Closure; use Exception; use LastDragon_ru\LaraASP\Core\Path\FilePath; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown as MarkdownContract; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; use LastDragon_ru\LaraASP\Documentator\Markdown\Extension; use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Generated\Block as GeneratedNode; @@ -88,7 +89,7 @@ public function testParse(): void { return trim((string) $renderer->renderDocument($document)); }; - $document = new Document( + $document = $this->app()->make(MarkdownContract::class)->parse( <<<'MARKDOWN' Text `💀App\Deprecated` text `App\ClassA` text [App\ClassB](https://example.com/) text [`\App\ClassC`](https://example.com/) text [`Class`](./class.php "App\ClassD") diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Context.php b/packages/documentator/src/Processor/Tasks/Preprocess/Context.php index 42dbf833..776865a5 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Context.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Context.php @@ -53,7 +53,7 @@ public function toSplittable(Document $document): Document { private function getMutation(Document $document): Mutation { $path = $this->file->getPath(); - $path = $path->getPath(new FilePath($document->getPath()?->getName() ?? '')); + $path = $path->getPath(new FilePath($document->path?->getName() ?? '')); return new Composite( new Move($path), diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeArtisan/InstructionTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeArtisan/InstructionTest.php index 16c560fc..bc93a047 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeArtisan/InstructionTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeArtisan/InstructionTest.php @@ -36,7 +36,7 @@ public function testInvoke(): void { $params = new Parameters('...'); $expected = 'result'; $command = 'command to execute'; - $context = new Context($root, $file, new Document(''), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); $instance = $this->app()->make(Instruction::class); $this->override(Kernel::class, static function (MockInterface $mock) use ($command, $expected): void { @@ -86,7 +86,7 @@ public function getDestination(): string { }; $params = new Parameters('...'); $command = $node->getDestination(); - $context = new Context($root, $file, new Document(''), $node, new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), $node, new Nop()); $instance = $this->app()->make(Instruction::class); $this->override(Kernel::class, static function (MockInterface $mock) use ($command): void { @@ -138,7 +138,7 @@ public function testGetCommand(): void { $file = new File((new FilePath(__FILE__))->getNormalizedPath(), false); $params = new Parameters('...'); $command = 'artisan:command $directory {$directory} "{$directory}" $file {$file} "{$file}"'; - $context = new Context($root, $file, new Document(''), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); $instance = new class (Mockery::mock(ApplicationResolver::class)) extends Instruction { #[Override] public function getCommand(Context $context, string $target, Parameters $parameters): string { diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocBlock/InstructionTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocBlock/InstructionTest.php index fe7189da..1cf3e049 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocBlock/InstructionTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocBlock/InstructionTest.php @@ -14,6 +14,7 @@ use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Instructions\IncludeDocBlock\Exceptions\TargetIsNotValidPhpFile; use LastDragon_ru\LaraASP\Documentator\Testing\Package\ProcessorHelper; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; +use Mockery; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; @@ -35,7 +36,7 @@ public function testInvoke(Closure|string $expected, string $file, Parameters $p $root = new Directory($path->getDirectoryPath(), false); $file = new File($path, false); $target = $file->getName(); - $context = new Context($root, $file, new Document(''), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); $instance = $this->app()->make(Instruction::class); if ($expected instanceof Closure) { @@ -52,7 +53,7 @@ public function testInvoke(Closure|string $expected, string $file, Parameters $p self::assertIsString($actual); } - self::assertEquals($expected, (string) $actual); + self::assertEquals($expected, trim((string) $actual)); } // diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocumentList/InstructionTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocumentList/InstructionTest.php index 319b6b7c..9640a9fc 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocumentList/InstructionTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocumentList/InstructionTest.php @@ -3,7 +3,7 @@ namespace LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Instructions\IncludeDocumentList; use LastDragon_ru\LaraASP\Core\Path\FilePath; -use LastDragon_ru\LaraASP\Documentator\Markdown\Document; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Nop; use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Reference\Block; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory; @@ -34,8 +34,8 @@ public function testInvoke(string $expected, string $path, string $content): voi $path = (new FilePath(self::getTestData()->path($path)))->getNormalizedPath(); $root = new Directory($path->getDirectoryPath(), false); $file = new File($path, false); - $document = new Document($content, $path); - $instruction = (new Query())->where(Query::type(Block::class))->findOne($document->getNode()); + $document = $this->app()->make(Markdown::class)->parse($content, $path); + $instruction = (new Query())->where(Query::type(Block::class))->findOne($document->node); self::assertInstanceOf(Block::class, $instruction); diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeExample/Instruction.php b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeExample/Instruction.php index 65b4ab65..a593ccc8 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeExample/Instruction.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeExample/Instruction.php @@ -4,7 +4,7 @@ use Generator; use LastDragon_ru\LaraASP\Core\Utils\Cast; -use LastDragon_ru\LaraASP\Documentator\Markdown\Document; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; use LastDragon_ru\LaraASP\Documentator\Processor\Contracts\Dependency; use LastDragon_ru\LaraASP\Documentator\Processor\Dependencies\FileReference; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File; @@ -38,6 +38,7 @@ class Instruction implements InstructionContract { protected const MarkdownRegexp = '/^\<(?Pmarkdown)\>(?P.*?)\<\/(?P=tag)\>$/msu'; public function __construct( + protected readonly Markdown $markdown, protected readonly ?Runner $runner = null, ) { // empty @@ -94,7 +95,7 @@ public function __invoke(Context $context, string $target, mixed $parameters): G subject : $output, flags : PREG_UNMATCHED_AS_NULL, ); - $output = new Document($output, $target->getPath()); + $output = $this->markdown->parse($output, $target->getPath()); $output = $context->toInlinable($output); $output = trim((string) $output); } diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeExample/InstructionTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeExample/InstructionTest.php index 6492ad02..24d2fcce 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeExample/InstructionTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeExample/InstructionTest.php @@ -12,6 +12,7 @@ use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Instructions\IncludeExample\Contracts\Runner; use LastDragon_ru\LaraASP\Documentator\Testing\Package\ProcessorHelper; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; +use Mockery; use Mockery\MockInterface; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; @@ -34,7 +35,7 @@ public function testInvoke(string $expected, string $output): void { $file = new File($path, false); $params = new Parameters('...'); $target = self::getTestData()->path('Example.md'); - $context = new Context($root, $file, new Document(''), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); $this->override(Runner::class, static function (MockInterface $mock) use ($target, $output): void { $mock @@ -60,7 +61,7 @@ public function testInvokeNoRun(): void { $file = new File($path, false); $params = new Parameters('...'); $target = $file->getName(); - $context = new Context($root, $file, new Document(''), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); $expected = trim($file->getContent()); $instance = $this->app()->make(Instruction::class); $actual = ProcessorHelper::runInstruction($instance, $context, $target, $params); diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeExec/InstructionTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeExec/InstructionTest.php index d80a6634..d2f4e81f 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeExec/InstructionTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeExec/InstructionTest.php @@ -14,6 +14,7 @@ use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Context; use LastDragon_ru\LaraASP\Documentator\Testing\Package\ProcessorHelper; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; +use Mockery; use PHPUnit\Framework\Attributes\CoversClass; /** @@ -27,7 +28,7 @@ public function testInvoke(): void { $params = new Parameters('...'); $expected = 'result'; $command = 'command to execute'; - $context = new Context($root, $file, new Document(''), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); $factory = $this->override(Factory::class, function () use ($command, $expected): Factory { $factory = $this->app()->make(Factory::class); $factory->preventStrayProcesses(); diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeFile/InstructionTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeFile/InstructionTest.php index 35ad1248..558e44c4 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeFile/InstructionTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeFile/InstructionTest.php @@ -12,6 +12,7 @@ use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Context; use LastDragon_ru\LaraASP\Documentator\Testing\Package\ProcessorHelper; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; +use Mockery; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; @@ -32,7 +33,7 @@ public function testInvoke(string $expected, string $source): void { $file = new File((new FilePath(__FILE__))->getNormalizedPath(), false); $params = new Parameters('...'); $target = self::getTestData()->path($source); - $context = new Context($root, $file, new Document(''), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); $instance = $this->app()->make(Instruction::class); $expected = self::getTestData()->content($expected); $actual = ProcessorHelper::runInstruction($instance, $context, $target, $params); diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeGraphqlDirective/InstructionTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeGraphqlDirective/InstructionTest.php index 368c0a34..783c783d 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeGraphqlDirective/InstructionTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeGraphqlDirective/InstructionTest.php @@ -54,7 +54,7 @@ public function testInvoke(): void { $file = Mockery::mock(File::class); $params = new Parameters('...'); $target = '@test'; - $context = new Context($root, $file, new Document(''), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); $instance = $this->app()->make(Instruction::class); $actual = ProcessorHelper::runInstruction($instance, $context, $target, $params); @@ -81,7 +81,7 @@ public function testInvokeNoPrinter(): void { $file = new File((new FilePath(__FILE__))->getNormalizedPath(), false); $params = new Parameters('...'); $target = '@test'; - $context = new Context($root, $file, new Document(''), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); $instance = $this->app()->make(Instruction::class); self::expectExceptionObject( @@ -109,7 +109,7 @@ public function testInvokeNoDirective(): void { $file = new File((new FilePath(__FILE__))->getNormalizedPath(), false); $params = new Parameters('...'); $target = '@test'; - $context = new Context($root, $file, new Document(''), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); $instance = $this->app()->make(Instruction::class); self::expectExceptionObject( @@ -128,7 +128,7 @@ public function testInvokeNoDirectiveResolver(): void { $file = new File((new FilePath(__FILE__))->getNormalizedPath(), false); $params = new Parameters('...'); $target = '@test'; - $context = new Context($root, $file, new Document(''), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); $instance = $this->app()->make(Instruction::class); self::expectExceptionObject( diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludePackageList/InstructionTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludePackageList/InstructionTest.php index e87ce37b..f006b2d6 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludePackageList/InstructionTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludePackageList/InstructionTest.php @@ -16,6 +16,7 @@ use LastDragon_ru\LaraASP\Documentator\Testing\Package\ProcessorHelper; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; use LastDragon_ru\LaraASP\Documentator\Utils\SortOrder; +use Mockery; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; @@ -34,7 +35,7 @@ public function testInvoke(string $expected, string $template, SortOrder $order) $file = new File($path, false); $target = $root->getDirectoryPath('packages'); $params = new Parameters('...', template: $template, order: $order); - $context = new Context($root, $file, new Document(''), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); $instance = $this->app()->make(Instruction::class); $actual = ProcessorHelper::runInstruction($instance, $context, $target, $params); @@ -55,7 +56,7 @@ public function testInvokeNoReadme(): void { $file = new File($path, false); $target = $root->getDirectoryPath('no readme'); $params = new Parameters('...'); - $context = new Context($root, $file, new Document(''), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); $instance = $this->app()->make(Instruction::class); $package = $fs->getDirectory(new Directory($target, false), 'package'); @@ -74,7 +75,7 @@ public function testInvokeEmptyReadme(): void { $file = new File($path, false); $target = $root->getDirectoryPath('empty readme'); $params = new Parameters('...'); - $context = new Context($root, $file, new Document(''), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); $instance = $this->app()->make(Instruction::class); $package = $fs->getDirectory(new Directory($target, false), 'package'); $expected = $fs->getFile($root, 'empty readme/package/README.md'); diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeTemplate/Instruction.php b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeTemplate/Instruction.php index 69b8bfaf..d859feb7 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeTemplate/Instruction.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeTemplate/Instruction.php @@ -4,6 +4,7 @@ use Generator; use LastDragon_ru\LaraASP\Core\Utils\Cast; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; use LastDragon_ru\LaraASP\Documentator\Processor\Contracts\Dependency; use LastDragon_ru\LaraASP\Documentator\Processor\Dependencies\FileReference; @@ -29,7 +30,9 @@ * @implements InstructionContract */ class Instruction implements InstructionContract { - public function __construct() { + public function __construct( + protected readonly Markdown $markdown, + ) { // empty } @@ -103,7 +106,7 @@ public function __invoke(Context $context, string $target, mixed $parameters): G // Markdown? if ($file->getExtension() === 'md') { - $content = new Document($content, $file->getPath()); + $content = $this->markdown->parse($content, $file->getPath()); } // Return diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeTemplate/InstructionTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeTemplate/InstructionTest.php index 55976282..24997f6f 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeTemplate/InstructionTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeTemplate/InstructionTest.php @@ -15,6 +15,7 @@ use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Instructions\IncludeTemplate\Exceptions\TemplateVariablesUnused; use LastDragon_ru\LaraASP\Documentator\Testing\Package\ProcessorHelper; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; +use Mockery; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; @@ -38,7 +39,7 @@ public function testInvoke(string $expected, string $source, array $data): void $file = new File((new FilePath(__FILE__))->getNormalizedPath(), false); $params = new Parameters('...', $data); $target = self::getTestData()->path($source); - $context = new Context($root, $file, new Document(''), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); $instance = $this->app()->make(Instruction::class); $expected = self::getTestData()->content($expected); $actual = ProcessorHelper::runInstruction($instance, $context, $target, $params); @@ -57,7 +58,7 @@ public function testInvokeNoData(): void { $file = new File((new FilePath(__FILE__))->getNormalizedPath(), false); $params = new Parameters('...', []); $target = $file->getPath(); - $context = new Context($root, $file, new Document(''), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); $instance = $this->app()->make(Instruction::class); self::expectExceptionObject( @@ -78,7 +79,7 @@ public function testInvokeVariablesUnused(): void { 'd' => 'D', ]); $target = $file->getPath(); - $context = new Context($root, $file, new Document(''), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); $instance = $this->app()->make(Instruction::class); self::expectExceptionObject( @@ -96,7 +97,7 @@ public function testInvokeVariablesMissed(): void { 'a' => 'A', ]); $target = $file->getPath(); - $context = new Context($root, $file, new Document(''), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); $instance = $this->app()->make(Instruction::class); self::expectExceptionObject( diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Mutations/InstructionsRemove.php b/packages/documentator/src/Processor/Tasks/Preprocess/Mutations/InstructionsRemove.php index e0234e89..043b93e8 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Mutations/InstructionsRemove.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Mutations/InstructionsRemove.php @@ -36,7 +36,7 @@ public function __invoke(Document $document): iterable { yield from []; // Update - foreach ($document->getNode()->iterator(NodeIterator::FLAG_BLOCKS_ONLY) as $node) { + foreach ($document->node->iterator(NodeIterator::FLAG_BLOCKS_ONLY) as $node) { // Instruction? if (!Utils::isInstruction($node, $this->instructions)) { continue; diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Mutations/InstructionsRemoveTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/Mutations/InstructionsRemoveTest.php index c91b4222..ce935d6a 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Mutations/InstructionsRemoveTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Mutations/InstructionsRemoveTest.php @@ -2,25 +2,19 @@ namespace LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Mutations; -use LastDragon_ru\LaraASP\Documentator\Editor\Editor; -use LastDragon_ru\LaraASP\Documentator\Markdown\Document; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; use LastDragon_ru\LaraASP\Documentator\Processor\InstanceList; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; -use League\CommonMark\Node\Block\Document as DocumentNode; use Mockery; -use Override; use PHPUnit\Framework\Attributes\CoversClass; -use function array_key_first; -use function array_values; - /** * @internal */ #[CoversClass(InstructionsRemove::class)] final class InstructionsRemoveTest extends TestCase { public function testInvoke(): void { - $markdown = <<<'MARKDOWN' + $content = <<<'MARKDOWN' # Header [test:instruction]: /path/to/file.md @@ -41,20 +35,6 @@ public function testInvoke(): void { [test]: /path/to/file.md MARKDOWN; - $document = new class($markdown) extends Document { - #[Override] - public function getNode(): DocumentNode { - return parent::getNode(); - } - - /** - * @inheritDoc - */ - #[Override] - public function getLines(): array { - return parent::getLines(); - } - }; $instructions = Mockery::mock(InstanceList::class); $instructions @@ -68,11 +48,9 @@ public function getLines(): array { ->once() ->andReturn(false); - $lines = $document->getLines(); - $offset = (int) array_key_first($lines); - $mutation = new InstructionsRemove($instructions); - $changes = $mutation($document); - $actual = (string) (new Editor(array_values($lines), $offset))->mutate($changes); + $markdown = $this->app()->make(Markdown::class); + $document = $markdown->parse($content); + $actual = (string) $document->mutate(new InstructionsRemove($instructions)); self::assertEquals( <<<'MARKDOWN' @@ -93,6 +71,7 @@ public function getLines(): array { [//]: # (end: block) [test]: /path/to/file.md + MARKDOWN, $actual, ); diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Task.php b/packages/documentator/src/Processor/Tasks/Preprocess/Task.php index 6804b373..f57dadb8 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Task.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Task.php @@ -202,7 +202,7 @@ protected function parse(Directory $root, File $file, Document $document): array $tokens = []; $mutation = new InstructionsRemove($this->instructions); - foreach ($document->getNode()->iterator(NodeIterator::FLAG_BLOCKS_ONLY) as $node) { + foreach ($document->node->iterator(NodeIterator::FLAG_BLOCKS_ONLY) as $node) { // Instruction? if (!Utils::isInstruction($node, $this->instructions)) { continue; diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/TaskTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/TaskTest.php index 0adafb42..bd64ff40 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/TaskTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/TaskTest.php @@ -5,6 +5,7 @@ use LastDragon_ru\LaraASP\Core\Application\ContainerResolver; use LastDragon_ru\LaraASP\Core\Path\FilePath; use LastDragon_ru\LaraASP\Documentator\Editor\Locations\Location; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown as MarkdownContract; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Location as LocationData; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory; @@ -89,7 +90,7 @@ public function parse(Directory $root, File $file, Document $document): array { $root = Mockery::mock(Directory::class); $file = Mockery::mock(File::class); - $document = new Document(self::MARKDOWN); + $document = $this->app()->make(MarkdownContract::class)->parse(self::MARKDOWN); $tokens = $task->parse($root, $file, $document); $actual = array_map( static function (array $tokens): array { @@ -159,9 +160,9 @@ static function (Token $token): array { public function testInvoke(): void { $task = $this->app()->make(Task::class) - ->addInstruction(new TaskTest__EmptyInstruction()) - ->addInstruction(new TaskTest__TestInstruction()) - ->addInstruction(new TaskTest__DocumentInstruction()); + ->addInstruction(TaskTest__EmptyInstruction::class) + ->addInstruction(TaskTest__TestInstruction::class) + ->addInstruction(TaskTest__DocumentInstruction::class); $actual = null; $path = new FilePath('path/to/file.md'); $file = Mockery::mock(File::class); @@ -180,8 +181,8 @@ static function (string $content) use ($file, &$actual): File { ->with(Mockery::type(Markdown::class)) ->once() ->andReturnUsing( - static function () use ($path): Document { - return new Document(static::MARKDOWN, $path); + function () use ($path): Document { + return $this->app()->make(MarkdownContract::class)->parse(static::MARKDOWN, $path); }, ); $file @@ -358,6 +359,12 @@ public function __invoke(Context $context, string $target, mixed $parameters): s * @implements Instruction */ class TaskTest__DocumentInstruction implements Instruction { + public function __construct( + protected readonly MarkdownContract $markdown, + ) { + // empty + } + #[Override] public static function getName(): string { return 'test:document'; @@ -375,7 +382,7 @@ public static function getParameters(): string { #[Override] public function __invoke(Context $context, string $target, mixed $parameters): Document { - return new Document( + return $this->markdown->parse( <<<'MARKDOWN' Summary [text](../Document.md) summary [link][link] and summary[^1] and [self](#fragment) and [self][self]. diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Utils.php b/packages/documentator/src/Processor/Tasks/Preprocess/Utils.php index 785cc3fb..28e2bba0 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Utils.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Utils.php @@ -31,7 +31,7 @@ public static function isInstruction(Node $node, InstanceList $instructions): bo } public static function getSeed(Context $context, Document|File $file): string { - $path = $file instanceof Document ? $file->getPath() : $file; + $path = $file instanceof Document ? $file->path : $file; $path = $path !== null ? (string) $context->root->getRelativePath($path) : ''; $path = $path !== '' ? $path : uniqid(self::class); // @phpstan-ignore disallowed.function $path = Text::hash($path); diff --git a/packages/documentator/src/Utils/PhpDoc.php b/packages/documentator/src/Utils/PhpDoc.php index 91f7b691..f295f7f4 100644 --- a/packages/documentator/src/Utils/PhpDoc.php +++ b/packages/documentator/src/Utils/PhpDoc.php @@ -2,11 +2,6 @@ namespace LastDragon_ru\LaraASP\Documentator\Utils; -use LastDragon_ru\LaraASP\Core\Path\FilePath; -use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\CodeLinks\Contracts\LinkFactory; -use PhpParser\NameContext; -use PhpParser\Node\Name; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode; use PHPStan\PhpDocParser\Lexer\Lexer; @@ -17,11 +12,8 @@ use function array_slice; use function implode; -use function preg_replace_callback; use function trim; -use const PREG_UNMATCHED_AS_NULL; - /** * @internal */ @@ -57,34 +49,6 @@ public function isDeprecated(): bool { return $this->node !== null && $this->node->getDeprecatedTagValues() !== []; } - public function getDocument(LinkFactory $factory, NameContext $context, ?FilePath $path = null): Document { - return new Document( - trim( - (string) preg_replace_callback( - pattern : '/\{@(?:see|link)\s+(?P[^}\s]+)\s?}/imu', - callback: static function (array $matches) use ($context, $factory): string { - $result = $matches[0]; - $reference = $factory->create( - $matches['reference'], - static function (string $class) use ($context): string { - return (string) $context->getResolvedClassName(new Name($class)); - }, - ); - - if ($reference !== null) { - $result = "`{$reference}`"; - } - - return $result; - }, - subject : $this->getText(), - flags : PREG_UNMATCHED_AS_NULL, - ), - ), - $path, - ); - } - /** * @param array $strings */ diff --git a/packages/documentator/src/Utils/PhpDocumentFactory.php b/packages/documentator/src/Utils/PhpDocumentFactory.php index b1da6982..0a34017b 100644 --- a/packages/documentator/src/Utils/PhpDocumentFactory.php +++ b/packages/documentator/src/Utils/PhpDocumentFactory.php @@ -3,16 +3,20 @@ namespace LastDragon_ru\LaraASP\Documentator\Utils; use LastDragon_ru\LaraASP\Core\Path\FilePath; +use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\CodeLinks\Contracts\LinkFactory; use PhpParser\NameContext; +use PhpParser\Node\Name; use PhpParser\NodeTraverser; use PhpParser\NodeVisitor\NameResolver; use PhpParser\ParserFactory; -use ReflectionClass; -use ReflectionProperty; use function file_get_contents; +use function preg_replace_callback; +use function trim; + +use const PREG_UNMATCHED_AS_NULL; /** * @internal @@ -24,31 +28,42 @@ class PhpDocumentFactory { private array $context = []; public function __construct( + protected readonly Markdown $markdown, protected readonly LinkFactory $factory, ) { // empty } - /** - * @param ReflectionClass|ReflectionProperty $object - */ - public function __invoke(ReflectionClass|ReflectionProperty $object): Document { - $document = null; - $path = match (true) { - $object instanceof ReflectionProperty => $object->getDeclaringClass()->getFileName(), - default => $object->getFileName(), - }; - - if ($path !== false) { - $phpdoc = new PhpDoc((string) $object->getDocComment()); - $context = $this->getContext($path); - $document = $phpdoc->getDocument($this->factory, $context, new FilePath($path)); - } else { - $phpdoc = new PhpDoc((string) $object->getDocComment()); - $document = new Document($phpdoc->getText(), null); + public function __invoke(PhpDoc $phpdoc, ?FilePath $path, ?NameContext $context = null): Document { + $text = $phpdoc->getText(); + + if ($path !== null) { + $context ??= $this->getContext((string) $path); + $text = trim( + (string) preg_replace_callback( + pattern : '/\{@(?:see|link)\s+(?P[^}\s]+)\s?}/imu', + callback: function (array $matches) use ($context): string { + $result = $matches[0]; + $reference = $this->factory->create( + $matches['reference'], + static function (string $class) use ($context): string { + return (string) $context->getResolvedClassName(new Name($class)); + }, + ); + + if ($reference !== null) { + $result = "`{$reference}`"; + } + + return $result; + }, + subject : $text, + flags : PREG_UNMATCHED_AS_NULL, + ), + ); } - return $document; + return $this->markdown->parse($text, $path); } private function getContext(string $path): NameContext { From 04419831fc64b24eecb87c7fd900fa55e950ca3c Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Mon, 9 Dec 2024 10:07:10 +0400 Subject: [PATCH 04/16] `\LastDragon_ru\LaraASP\Documentator\Markdown\Nodes` namespace renamed to `\LastDragon_ru\LaraASP\Documentator\Markdown\Extensions`. --- packages/documentator/src/Markdown/Extension.php | 8 ++++---- .../src/Markdown/{Nodes => Extensions}/Aware.php | 2 +- .../Markdown/{Nodes => Extensions}/Generated/Block.php | 2 +- .../Generated/Data/EndMarkerLocation.php | 2 +- .../Generated/Data/StartMarkerLocation.php | 2 +- .../{Nodes => Extensions}/Generated/ParserContinue.php | 6 +++--- .../{Nodes => Extensions}/Generated/ParserStart.php | 2 +- .../{Nodes => Extensions}/Generated/ParserTest.php | 8 ++++---- .../Generated/ParserTest~document.md | 0 .../Generated/ParserTest~expected.xml | 0 .../{Nodes => Extensions}/Generated/Renderer.php | 8 ++++---- .../{Nodes => Extensions}/Locator/Listener.php | 2 +- .../Markdown/{Nodes => Extensions}/Locator/Parser.php | 4 ++-- .../{Nodes => Extensions}/Locator/ParserTest.php | 8 ++++---- .../Locator/ParserTest~document.md | 0 .../Locator/ParserTest~expected.xml | 0 .../Markdown/{Nodes => Extensions}/Reference/Block.php | 2 +- .../{Nodes => Extensions}/Reference/Parser.php | 2 +- .../{Nodes => Extensions}/Reference/ParserContinue.php | 2 +- .../{Nodes => Extensions}/Reference/ParserStart.php | 2 +- .../{Nodes => Extensions}/Reference/ParserTest.php | 4 ++-- .../Reference/ParserTest~document.md | 0 .../Reference/ParserTest~expected.xml | 0 .../{Nodes => Extensions}/Reference/Renderer.php | 2 +- .../Markdown/{Nodes => Extensions}/RendererWrapper.php | 2 +- .../src/Markdown/{Nodes => Extensions}/XmlRenderer.php | 2 +- .../src/Markdown/Mutations/Document/Move.php | 2 +- .../src/Markdown/Mutations/Generated/Unwrap.php | 6 +++--- .../src/Markdown/Mutations/Reference/Inline.php | 2 +- .../src/Markdown/Mutations/Reference/Prefix.php | 2 +- .../src/Processor/Tasks/CodeLinks/Task.php | 3 +-- .../src/Processor/Tasks/CodeLinks/TaskTest.php | 10 +++++----- .../src/Processor/Tasks/Preprocess/Context.php | 2 +- .../Instructions/IncludeArtisan/InstructionTest.php | 3 +-- .../Instructions/IncludeDocBlock/InstructionTest.php | 3 +-- .../Instructions/IncludeDocumentList/Instruction.php | 2 +- .../IncludeDocumentList/InstructionTest.php | 4 +--- .../Instructions/IncludeExample/InstructionTest.php | 3 +-- .../Instructions/IncludeExec/InstructionTest.php | 2 +- .../Instructions/IncludeFile/InstructionTest.php | 4 +--- .../IncludeGraphqlDirective/InstructionTest.php | 2 +- .../IncludePackageList/InstructionTest.php | 2 +- .../Instructions/IncludeTemplate/InstructionTest.php | 4 +--- .../src/Processor/Tasks/Preprocess/Task.php | 4 +--- .../src/Processor/Tasks/Preprocess/Token.php | 2 +- .../src/Processor/Tasks/Preprocess/Utils.php | 4 ++-- 46 files changed, 63 insertions(+), 75 deletions(-) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Aware.php (93%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Generated/Block.php (93%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Generated/Data/EndMarkerLocation.php (77%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Generated/Data/StartMarkerLocation.php (77%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Generated/ParserContinue.php (93%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Generated/ParserStart.php (95%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Generated/ParserTest.php (78%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Generated/ParserTest~document.md (100%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Generated/ParserTest~expected.xml (100%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Generated/Renderer.php (67%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Locator/Listener.php (98%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Locator/Parser.php (98%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Locator/ParserTest.php (89%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Locator/ParserTest~document.md (100%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Locator/ParserTest~expected.xml (100%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Reference/Block.php (91%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Reference/Parser.php (96%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Reference/ParserContinue.php (97%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Reference/ParserStart.php (93%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Reference/ParserTest.php (92%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Reference/ParserTest~document.md (100%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Reference/ParserTest~expected.xml (100%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/Reference/Renderer.php (93%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/RendererWrapper.php (98%) rename packages/documentator/src/Markdown/{Nodes => Extensions}/XmlRenderer.php (84%) diff --git a/packages/documentator/src/Markdown/Extension.php b/packages/documentator/src/Markdown/Extension.php index b30d29b2..88e446c5 100644 --- a/packages/documentator/src/Markdown/Extension.php +++ b/packages/documentator/src/Markdown/Extension.php @@ -4,10 +4,10 @@ use LastDragon_ru\LaraASP\Documentator\Editor\Coordinate; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Input; -use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Generated\ParserStart as GenerateParser; -use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Locator\Listener; -use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Locator\Parser; -use LastDragon_ru\LaraASP\Documentator\Markdown\Nodes\Reference\ParserStart as ReferenceParser; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated\ParserStart as GenerateParser; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Locator\Listener; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Locator\Parser; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\ParserStart as ReferenceParser; use League\CommonMark\Environment\EnvironmentBuilderInterface; use League\CommonMark\Event\DocumentParsedEvent; use League\CommonMark\Event\DocumentPreParsedEvent; diff --git a/packages/documentator/src/Markdown/Nodes/Aware.php b/packages/documentator/src/Markdown/Extensions/Aware.php similarity index 93% rename from packages/documentator/src/Markdown/Nodes/Aware.php rename to packages/documentator/src/Markdown/Extensions/Aware.php index 65875738..1f9586c3 100644 --- a/packages/documentator/src/Markdown/Nodes/Aware.php +++ b/packages/documentator/src/Markdown/Extensions/Aware.php @@ -1,6 +1,6 @@ Date: Tue, 10 Dec 2024 10:58:51 +0400 Subject: [PATCH 05/16] Better XML renderer for tests. --- composer-require-checker.json | 1 + composer.json | 1 + packages/documentator/composer.json | 1 + .../documentator/src/Markdown/Data/Data.php | 2 +- .../src/Markdown/MarkdownTest.php | 27 + .../src/Markdown/MarkdownTest~document.md | 46 + .../src/Markdown/MarkdownTest~expected.xml | 1129 +++++++++++++++++ .../src/Testing/Package/DocumentRenderer.php | 310 +++++ 8 files changed, 1516 insertions(+), 1 deletion(-) create mode 100644 packages/documentator/src/Markdown/MarkdownTest.php create mode 100644 packages/documentator/src/Markdown/MarkdownTest~document.md create mode 100644 packages/documentator/src/Markdown/MarkdownTest~expected.xml create mode 100644 packages/documentator/src/Testing/Package/DocumentRenderer.php diff --git a/composer-require-checker.json b/composer-require-checker.json index c8bc4f17..2e7e2d3d 100644 --- a/composer-require-checker.json +++ b/composer-require-checker.json @@ -1,5 +1,6 @@ { "symbol-whitelist": [ + "XMLWriter", "Composer\\ClassMapGenerator\\ClassMapGenerator", "Composer\\InstalledVersions", "Faker\\Factory", diff --git a/composer.json b/composer.json index 3fffdbb7..6fda83c3 100644 --- a/composer.json +++ b/composer.json @@ -92,6 +92,7 @@ "webonyx/graphql-php": "^15.4.0" }, "require-dev": { + "ext-xmlwriter": "*", "ext-pdo_sqlite": "*", "bamarni/composer-bin-plugin": "^1.8", "composer/class-map-generator": "^1.0", diff --git a/packages/documentator/composer.json b/packages/documentator/composer.json index 8961020a..63aac8d9 100644 --- a/packages/documentator/composer.json +++ b/packages/documentator/composer.json @@ -43,6 +43,7 @@ "lastdragon-ru/lara-asp-serializer": "self.version" }, "require-dev": { + "ext-xmlwriter": "*", "lastdragon-ru/lara-asp-testing": "self.version", "mockery/mockery": "^1.6.5", "orchestra/testbench": "^9.0.0", diff --git a/packages/documentator/src/Markdown/Data/Data.php b/packages/documentator/src/Markdown/Data/Data.php index 93521fb7..3224c38e 100644 --- a/packages/documentator/src/Markdown/Data/Data.php +++ b/packages/documentator/src/Markdown/Data/Data.php @@ -17,7 +17,7 @@ final public function __construct( /** * @var T */ - protected mixed $value, + public mixed $value, ) { // empty } diff --git a/packages/documentator/src/Markdown/MarkdownTest.php b/packages/documentator/src/Markdown/MarkdownTest.php new file mode 100644 index 00000000..98db15bd --- /dev/null +++ b/packages/documentator/src/Markdown/MarkdownTest.php @@ -0,0 +1,27 @@ +app()->make(DocumentRenderer::class); + $markdown = $this->app()->make(Markdown::class); + $document = $markdown->parse(self::getTestData()->content('~document.md')); + $lines = Lines::optional()->get($document->node); + + self::assertIsArray($lines); + self::assertEquals( + self::getTestData()->content('~expected.xml'), + $renderer->render($document), + ); + } +} diff --git a/packages/documentator/src/Markdown/MarkdownTest~document.md b/packages/documentator/src/Markdown/MarkdownTest~document.md new file mode 100644 index 00000000..e45ba5ad --- /dev/null +++ b/packages/documentator/src/Markdown/MarkdownTest~document.md @@ -0,0 +1,46 @@ +# Generated[^1] + +[//]: # (start: block) + +Text text text text text text text text text text text text text +text text text text text text text text text text text text text +text text text text text text text text text text text text. + +[//]: # (start: nested) + +Nested should be ignored. + +[//]: # (end: nested) + +[//]: # (end: block) + +> Quote +> [//]: # (start: quote) +> should work +> [//]: # (end: quote) + +# References + +[simple]: https://example.com/ + +[multiline]: +https://example.com/ +( + example.com +) + +> Quote +> +> [quote]: +> https://example.com/ + +# Tables + +| Header | Header ([link](https://example.com/)) | +|--------------------------|-------------------------------------------------------------| +| Cell [link][quote] cell. | Cell | +| Cell | Cell cell [link](https://example.com/) cell [link][simple]. | + +# Footnotes + +[^1]: Footnote text text text text diff --git a/packages/documentator/src/Markdown/MarkdownTest~expected.xml b/packages/documentator/src/Markdown/MarkdownTest~expected.xml new file mode 100644 index 00000000..6abf5b4d --- /dev/null +++ b/packages/documentator/src/Markdown/MarkdownTest~expected.xml @@ -0,0 +1,1129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Quote]]> + + + [//]: # (start: quote)]]> + + + should work]]> + + + [//]: # (end: quote)]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Quote]]> + + + ]]> + + + [quote]:]]> + + + https://example.com/]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + 2 + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + 4 + + + 9 + + + 1 + + + 2 + + + + + + + + + + + + + 0 + + + + + 16 + + + + + + + + + 0 + + + 15 + + + 0 + + + + + + + 4 + + + + + + + + + 0 + + + 3 + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + 20 + + + + + + + + + 0 + + + 20 + + + 2 + + + + + + + 18 + + + + + + + + + 0 + + + 18 + + + 2 + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + 26 + + + 1 + + + 1 + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 61 + + + 28 + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 39 + + + + + + 28 + + + 36 + + + 39 + + + 1 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + 26 + + + 1 + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 41 + + + + + + 13 + + + 6 + + + 41 + + + 1 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 61 + + + 28 + + + 1 + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + 26 + + + 1 + + + 1 + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 61 + + + 28 + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 42 + + + + + + 28 + + + 38 + + + 42 + + + 1 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 42 + + + + + + 14 + + + 72 + + + 42 + + + 1 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/documentator/src/Testing/Package/DocumentRenderer.php b/packages/documentator/src/Testing/Package/DocumentRenderer.php new file mode 100644 index 00000000..8ac9c1e7 --- /dev/null +++ b/packages/documentator/src/Testing/Package/DocumentRenderer.php @@ -0,0 +1,310 @@ +, ?XmlNodeRendererInterface> + */ + private array $renderers = []; + /** + * @var Closure(string,string): int + */ + private Closure $sort; + private ?EnvironmentInterface $env; + + private XMLWriter $xml; + + public function __construct(Sorter $sorter) { + $this->sort = $sorter->forString(SortOrder::Asc); + $this->xml = new XMLWriter(); + $this->env = null; + } + + public function render(Document $document): string { + try { + $this->env = $this->getEnvironment($document); + + $this->xml->openMemory(); + $this->xml->setIndent(true); + $this->xml->setIndentString(' '); + $this->xml->startDocument(encoding: 'UTF-8'); + $this->xml->startElement('markdown'); + + $this->writeNode($document->node); + + $this->xml->endElement(); + $this->xml->endDocument(); + + return $this->xml->outputMemory(); + } finally { + $this->reset(); + } + } + + private function reset(): void { + $this->renderers = []; + $this->xml = new XMLWriter(); + $this->env = null; + } + + private function writeNode(Node $node): void { + $renderer = $this->getRenderer($node::class); + + $this->xml->startElement('node'); + + if ($renderer !== null) { + $this->xml->writeAttribute('name', $renderer->getXmlTagName($node)); + $this->writeAttributes($renderer->getXmlAttributes($node)); + } else { + $this->xml->writeAttribute('class', $node::class); + } + + $this->writeData($node->data->export()); + + foreach ($node->children() as $child) { + $this->writeNode($child); + } + + if ($node instanceof StringContainerInterface) { + $this->writeValue($node->getLiteral()); + } + + $this->xml->endElement(); + } + + /** + * @param array $attributes + */ + private function writeAttributes(array $attributes): void { + // Empty? + if ($attributes === []) { + return; + } + + // Write + $this->xml->startElement('attributes'); + + foreach ($this->sort($attributes) as $attribute => $value) { + $this->writeAttribute($attribute, $value); + } + + $this->xml->endElement(); + } + + private function writeAttribute(string $attribute, mixed $value): void { + $this->writeKeyValue('attribute', 'name', $attribute, $value); + } + + /** + * @param array $data + */ + private function writeData(array $data): void { + // Empty? + if ($data === []) { + return; + } + + // Write + $this->xml->startElement('data'); + + foreach ($this->sort($data) as $key => $value) { + $this->writeDataItem($key, $value); + } + + $this->xml->endElement(); + } + + private function writeDataItem(string $key, mixed $value): void { + $this->writeArrayItem($key, $value); + } + + private function writeValue(mixed $value): void { + if ($value === null) { + $this->xml->writeElement('null'); + } elseif (is_bool($value)) { + $this->xml->writeElement('bool', $value ? 'true' : 'false'); + } elseif (is_string($value)) { + $this->xml->startElement('string'); + $this->xml->writeCdata($value); + $this->xml->endElement(); + } elseif (is_float($value)) { + $this->xml->writeElement('float', var_export($value, true)); + } elseif (is_int($value)) { + $this->xml->writeElement('int', var_export($value, true)); + } elseif (is_array($value)) { + $this->writeArray($value); + } elseif (is_object($value)) { + $this->writeObject($value); + } else { + throw new Exception('Not implemented.'); + } + } + + private function writeObject(object $object): void { + // Wrapper? + if ($object instanceof Data) { + $this->writeValue($object->value); + + return; + } + + // Nope + $this->xml->startElement('object'); + $this->xml->writeAttribute('class', $object::class); + + $properties = $this->getObjectProperties($object); + $properties = $this->sort($properties); + + foreach ($properties as $property => $value) { + $this->writeObjectProperty($property, $value); + } + + $this->xml->endElement(); + } + + private function writeObjectProperty(string $property, mixed $value): void { + $this->writeKeyValue('property', 'name', $property, $value); + } + + /** + * @param array $array + */ + private function writeArray(array $array): void { + $this->xml->startElement('array'); + $this->xml->writeAttribute('length', (string) count($array)); + + foreach ($array as $key => $value) { + $this->writeArrayItem($key, $value); + } + + $this->xml->endElement(); + } + + private function writeArrayItem(string|int $key, mixed $value): void { + $this->writeKeyValue('item', 'key', $key, $value); + } + + private function writeKeyValue(string $element, string $attribute, string|int $key, mixed $value): void { + $this->xml->startElement($element); + $this->xml->writeAttribute($attribute, (string) $key); + + $this->writeValue($value); + + $this->xml->endElement(); + } + + /** + * @return array + */ + private function getObjectProperties(object $object): array { + $properties = get_object_vars($object); + $additional = match (true) { + $object instanceof ReferenceInterface => [ + 'label' => $object->getLabel(), + 'title' => $object->getTitle(), + 'destination' => $object->getDestination(), + ], + default => [], + }; + + return $properties + $additional; + } + + /** + * @template T of array-key + * + * @param array $array + * + * @return array + */ + private function sort(array $array): array { + uksort($array, $this->sort); + + return $array; + } + + private function getEnvironment(Document $document): ?EnvironmentInterface { + $documentWrapper = new class ($document) extends Document { + /** + * @noinspection PhpMissingParentConstructorInspection + * @phpstan-ignore-next-line constructor.missingParentCall (no need to call parent `__construct`) + */ + public function __construct( + private readonly Document $document, + ) { + // empty + } + + public function getMarkdown(): MarkdownContract { + return $this->document->markdown; + } + }; + $markdownWrapper = new class ($documentWrapper->getMarkdown()) extends Markdown { + /** + * @noinspection PhpMissingParentConstructorInspection + * @phpstan-ignore-next-line constructor.missingParentCall (no need to call parent `__construct`) + */ + public function __construct( + private readonly MarkdownContract $markdown, + ) { + // empty + } + + public function getEnvironment(): ?EnvironmentInterface { + return $this->markdown instanceof Markdown ? $this->markdown->environment : null; + } + }; + $environment = $markdownWrapper->getEnvironment(); + + return $environment; + } + + /** + * @param class-string $class + */ + private function getRenderer(string $class): ?XmlNodeRendererInterface { + if (!array_key_exists($class, $this->renderers)) { + $this->renderers[$class] = null; + + foreach ($this->env?->getRenderersForClass($class) ?? [] as $renderer) { + if ($renderer instanceof XmlNodeRendererInterface) { + $this->renderers[$class] = $renderer; + break; + } + } + } + + return $this->renderers[$class]; + } +} From 794a843f49c0d3042c6b3a46585ee66ac1657135 Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Tue, 10 Dec 2024 10:59:52 +0400 Subject: [PATCH 06/16] Extracted `\LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated\Extension`. --- .../documentator/src/Markdown/Extension.php | 2 -- .../Extensions/Generated/Extension.php | 26 +++++++++++++++++++ .../{ParserTest.php => ExtensionTest.php} | 7 ++--- ...~document.md => ExtensionTest~document.md} | 0 ...xpected.xml => ExtensionTest~expected.xml} | 11 ++++---- .../documentator/src/Markdown/Markdown.php | 4 ++- 6 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 packages/documentator/src/Markdown/Extensions/Generated/Extension.php rename packages/documentator/src/Markdown/Extensions/Generated/{ParserTest.php => ExtensionTest.php} (75%) rename packages/documentator/src/Markdown/Extensions/Generated/{ParserTest~document.md => ExtensionTest~document.md} (100%) rename packages/documentator/src/Markdown/Extensions/Generated/{ParserTest~expected.xml => ExtensionTest~expected.xml} (76%) diff --git a/packages/documentator/src/Markdown/Extension.php b/packages/documentator/src/Markdown/Extension.php index 88e446c5..aa98b33f 100644 --- a/packages/documentator/src/Markdown/Extension.php +++ b/packages/documentator/src/Markdown/Extension.php @@ -4,7 +4,6 @@ use LastDragon_ru\LaraASP\Documentator\Editor\Coordinate; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Input; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated\ParserStart as GenerateParser; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Locator\Listener; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Locator\Parser; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\ParserStart as ReferenceParser; @@ -39,7 +38,6 @@ public function register(EnvironmentBuilderInterface $environment): void { $environment ->addExtension(new FootnoteExtension()) ->addBlockStartParser($referenceParser) - ->addBlockStartParser(new GenerateParser(), 100) ->addInlineParser(new Parser(new CloseBracketParser()), 100) ->addInlineParser(new Parser(new FootnoteRefParser()), 100) ->addInlineParser(new Parser(new BacktickParser()), 200) diff --git a/packages/documentator/src/Markdown/Extensions/Generated/Extension.php b/packages/documentator/src/Markdown/Extensions/Generated/Extension.php new file mode 100644 index 00000000..ec1feca1 --- /dev/null +++ b/packages/documentator/src/Markdown/Extensions/Generated/Extension.php @@ -0,0 +1,26 @@ +addBlockStartParser(new ParserStart(), 100); + } +} diff --git a/packages/documentator/src/Markdown/Extensions/Generated/ParserTest.php b/packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest.php similarity index 75% rename from packages/documentator/src/Markdown/Extensions/Generated/ParserTest.php rename to packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest.php index f6d5fb0c..02783705 100644 --- a/packages/documentator/src/Markdown/Extensions/Generated/ParserTest.php +++ b/packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest.php @@ -2,9 +2,6 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extension; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block as ReferenceBlock; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Renderer as ReferenceRenderer; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\RendererWrapper; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; use League\CommonMark\GithubFlavoredMarkdownConverter; @@ -15,14 +12,14 @@ /** * @internal */ +#[CoversClass(Extension::class)] #[CoversClass(ParserStart::class)] #[CoversClass(ParserContinue::class)] -final class ParserTest extends TestCase { +final class ExtensionTest extends TestCase { public function testParse(): void { $converter = new GithubFlavoredMarkdownConverter(); $environment = $converter->getEnvironment() ->addExtension(new Extension()) - ->addRenderer(ReferenceBlock::class, new RendererWrapper(new ReferenceRenderer())) ->addRenderer(Block::class, new RendererWrapper(new Renderer())); $parser = new MarkdownParser($environment); diff --git a/packages/documentator/src/Markdown/Extensions/Generated/ParserTest~document.md b/packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest~document.md similarity index 100% rename from packages/documentator/src/Markdown/Extensions/Generated/ParserTest~document.md rename to packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest~document.md diff --git a/packages/documentator/src/Markdown/Extensions/Generated/ParserTest~expected.xml b/packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest~expected.xml similarity index 76% rename from packages/documentator/src/Markdown/Extensions/Generated/ParserTest~expected.xml rename to packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest~expected.xml index 7e7ae5f0..17ffac3c 100644 --- a/packages/documentator/src/Markdown/Extensions/Generated/ParserTest~expected.xml +++ b/packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest~expected.xml @@ -13,7 +13,6 @@ ... nope ... - Text text text text text text text text text text text text text @@ -22,11 +21,9 @@ text text text text text text text text text text text text. - Nested should be ignored. - @@ -40,15 +37,17 @@ Text text text. - Nested should be ignored. + + + // + + : # (end: nested) - - Up to the end. diff --git a/packages/documentator/src/Markdown/Markdown.php b/packages/documentator/src/Markdown/Markdown.php index 36696318..ddc2b932 100644 --- a/packages/documentator/src/Markdown/Markdown.php +++ b/packages/documentator/src/Markdown/Markdown.php @@ -4,6 +4,7 @@ use LastDragon_ru\LaraASP\Core\Path\FilePath; use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown as MarkdownContract; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated\Extension as GeneratedExtension; use League\CommonMark\Environment\Environment; use League\CommonMark\Environment\EnvironmentInterface; use League\CommonMark\GithubFlavoredMarkdownConverter; @@ -22,7 +23,8 @@ public function __construct() { protected function initialize(): Environment { return (new GithubFlavoredMarkdownConverter())->getEnvironment() - ->addExtension(new Extension()); + ->addExtension(new Extension()) + ->addExtension(new GeneratedExtension()); } #[Override] From 717cb91bfb24e9a6c40cf7e69b0eb7554812a2fc Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Tue, 10 Dec 2024 11:36:48 +0400 Subject: [PATCH 07/16] Extracted `\LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Core\Extension`. --- .../documentator/src/Markdown/Extension.php | 3 - .../src/Markdown/ExtensionTest.php | 45 -------- .../Markdown/Extensions/Core/Extension.php | 25 +++++ .../Extensions/Core/ExtensionTest.php | 41 +++++++ .../Extensions/Core/ExtensionTest~document.md | 5 + .../Core/ExtensionTest~document.xml | 102 ++++++++++++++++++ .../Extensions/Locator/ParserTest.php | 2 + .../documentator/src/Markdown/Markdown.php | 2 + 8 files changed, 177 insertions(+), 48 deletions(-) delete mode 100644 packages/documentator/src/Markdown/ExtensionTest.php create mode 100644 packages/documentator/src/Markdown/Extensions/Core/Extension.php create mode 100644 packages/documentator/src/Markdown/Extensions/Core/ExtensionTest.php create mode 100644 packages/documentator/src/Markdown/Extensions/Core/ExtensionTest~document.md create mode 100644 packages/documentator/src/Markdown/Extensions/Core/ExtensionTest~document.xml diff --git a/packages/documentator/src/Markdown/Extension.php b/packages/documentator/src/Markdown/Extension.php index aa98b33f..e5439e53 100644 --- a/packages/documentator/src/Markdown/Extension.php +++ b/packages/documentator/src/Markdown/Extension.php @@ -3,7 +3,6 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown; use LastDragon_ru\LaraASP\Documentator\Editor\Coordinate; -use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Input; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Locator\Listener; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Locator\Parser; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\ParserStart as ReferenceParser; @@ -44,8 +43,6 @@ public function register(EnvironmentBuilderInterface $environment): void { ->addEventListener( DocumentPreParsedEvent::class, static function (DocumentPreParsedEvent $event) use ($referenceParser): void { - Input::set($event->getDocument(), $event->getMarkdown()); - $referenceParser->setReferenceMap($event->getDocument()->getReferenceMap()); }, ) diff --git a/packages/documentator/src/Markdown/ExtensionTest.php b/packages/documentator/src/Markdown/ExtensionTest.php deleted file mode 100644 index f98a8ee3..00000000 --- a/packages/documentator/src/Markdown/ExtensionTest.php +++ /dev/null @@ -1,45 +0,0 @@ -getEnvironment() - ->addExtension(new Extension()); - - $parser = new MarkdownParser($environment); - $markdown = "# Header\nParagraph [link](https://example.com/)."; - $document = $parser->parse($markdown); - $lines = Lines::optional()->get($document); - $link = (new Query())->where(Query::type(Link::class))->findOne($document); - - self::assertIsArray($lines); - self::assertCount(2, $lines); - self::assertNotNull($link); - self::assertEquals( - [ - new Coordinate(2, 10, 28), - ], - iterator_to_array( - Location::optional()->get($link) ?? [], - ), - ); - } -} diff --git a/packages/documentator/src/Markdown/Extensions/Core/Extension.php b/packages/documentator/src/Markdown/Extensions/Core/Extension.php new file mode 100644 index 00000000..a6464d8c --- /dev/null +++ b/packages/documentator/src/Markdown/Extensions/Core/Extension.php @@ -0,0 +1,25 @@ +addEventListener( + DocumentPreParsedEvent::class, + static function (DocumentPreParsedEvent $event): void { + Input::set($event->getDocument(), $event->getMarkdown()); + }, + ); + } +} diff --git a/packages/documentator/src/Markdown/Extensions/Core/ExtensionTest.php b/packages/documentator/src/Markdown/Extensions/Core/ExtensionTest.php new file mode 100644 index 00000000..072fb043 --- /dev/null +++ b/packages/documentator/src/Markdown/Extensions/Core/ExtensionTest.php @@ -0,0 +1,41 @@ +getEnvironment() + ->addExtension(new Extension()); + + return $environment; + } + }; + + $renderer = $this->app()->make(DocumentRenderer::class); + $document = $markdown->parse(self::getTestData()->content('~document.md')); + $lines = Lines::optional()->get($document->node); + + self::assertIsArray($lines); + self::assertEquals( + self::getTestData()->content('~document.xml'), + $renderer->render($document), + ); + } +} diff --git a/packages/documentator/src/Markdown/Extensions/Core/ExtensionTest~document.md b/packages/documentator/src/Markdown/Extensions/Core/ExtensionTest~document.md new file mode 100644 index 00000000..d3923bb5 --- /dev/null +++ b/packages/documentator/src/Markdown/Extensions/Core/ExtensionTest~document.md @@ -0,0 +1,5 @@ +# Core + +Text text text text text text text text text text text text text +text text text text text text text text text text text text text +text text text text text text text text text text text text. diff --git a/packages/documentator/src/Markdown/Extensions/Core/ExtensionTest~document.xml b/packages/documentator/src/Markdown/Extensions/Core/ExtensionTest~document.xml new file mode 100644 index 00000000..ef48b851 --- /dev/null +++ b/packages/documentator/src/Markdown/Extensions/Core/ExtensionTest~document.xml @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/documentator/src/Markdown/Extensions/Locator/ParserTest.php b/packages/documentator/src/Markdown/Extensions/Locator/ParserTest.php index 79417860..982cf970 100644 --- a/packages/documentator/src/Markdown/Extensions/Locator/ParserTest.php +++ b/packages/documentator/src/Markdown/Extensions/Locator/ParserTest.php @@ -3,6 +3,7 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Locator; use LastDragon_ru\LaraASP\Documentator\Markdown\Extension; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Core\Extension as CoreExtension; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block as ReferenceNode; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Renderer as ReferenceRenderer; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\RendererWrapper; @@ -37,6 +38,7 @@ public function testParse(): void { $converter = new GithubFlavoredMarkdownConverter(); $environment = $converter->getEnvironment() ->addExtension(new Extension()) + ->addExtension(new CoreExtension()) ->addRenderer(Link::class, new RendererWrapper(new LinkRenderer())) ->addRenderer(Image::class, new RendererWrapper(new ImageRenderer())) ->addRenderer(Footnote::class, new RendererWrapper(new FootnoteRenderer())) diff --git a/packages/documentator/src/Markdown/Markdown.php b/packages/documentator/src/Markdown/Markdown.php index ddc2b932..85cebee7 100644 --- a/packages/documentator/src/Markdown/Markdown.php +++ b/packages/documentator/src/Markdown/Markdown.php @@ -4,6 +4,7 @@ use LastDragon_ru\LaraASP\Core\Path\FilePath; use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown as MarkdownContract; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Core\Extension as CoreExtension; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated\Extension as GeneratedExtension; use League\CommonMark\Environment\Environment; use League\CommonMark\Environment\EnvironmentInterface; @@ -24,6 +25,7 @@ public function __construct() { protected function initialize(): Environment { return (new GithubFlavoredMarkdownConverter())->getEnvironment() ->addExtension(new Extension()) + ->addExtension(new CoreExtension()) ->addExtension(new GeneratedExtension()); } From 390c36444b45cb387fcb6877d996e2b33f4f0c24 Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Tue, 10 Dec 2024 11:48:00 +0400 Subject: [PATCH 08/16] Extracted `\LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Locator\Extension`. --- .../documentator/src/Markdown/Extension.php | 15 --------- .../Markdown/Extensions/Locator/Extension.php | 31 +++++++++++++++++++ .../{ParserTest.php => ExtensionTest.php} | 8 +++-- ...~document.md => ExtensionTest~document.md} | 0 ...xpected.xml => ExtensionTest~expected.xml} | 1 - .../documentator/src/Markdown/Markdown.php | 6 +++- 6 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 packages/documentator/src/Markdown/Extensions/Locator/Extension.php rename packages/documentator/src/Markdown/Extensions/Locator/{ParserTest.php => ExtensionTest.php} (94%) rename packages/documentator/src/Markdown/Extensions/Locator/{ParserTest~document.md => ExtensionTest~document.md} (100%) rename packages/documentator/src/Markdown/Extensions/Locator/{ParserTest~expected.xml => ExtensionTest~expected.xml} (99%) diff --git a/packages/documentator/src/Markdown/Extension.php b/packages/documentator/src/Markdown/Extension.php index e5439e53..23ab56e5 100644 --- a/packages/documentator/src/Markdown/Extension.php +++ b/packages/documentator/src/Markdown/Extension.php @@ -3,17 +3,10 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown; use LastDragon_ru\LaraASP\Documentator\Editor\Coordinate; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Locator\Listener; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Locator\Parser; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\ParserStart as ReferenceParser; use League\CommonMark\Environment\EnvironmentBuilderInterface; -use League\CommonMark\Event\DocumentParsedEvent; use League\CommonMark\Event\DocumentPreParsedEvent; -use League\CommonMark\Extension\CommonMark\Parser\Inline\BacktickParser; -use League\CommonMark\Extension\CommonMark\Parser\Inline\CloseBracketParser; use League\CommonMark\Extension\ExtensionInterface; -use League\CommonMark\Extension\Footnote\FootnoteExtension; -use League\CommonMark\Extension\Footnote\Parser\FootnoteRefParser; use Override; /** @@ -35,20 +28,12 @@ public function register(EnvironmentBuilderInterface $environment): void { $referenceParser = new ReferenceParser(); $environment - ->addExtension(new FootnoteExtension()) ->addBlockStartParser($referenceParser) - ->addInlineParser(new Parser(new CloseBracketParser()), 100) - ->addInlineParser(new Parser(new FootnoteRefParser()), 100) - ->addInlineParser(new Parser(new BacktickParser()), 200) ->addEventListener( DocumentPreParsedEvent::class, static function (DocumentPreParsedEvent $event) use ($referenceParser): void { $referenceParser->setReferenceMap($event->getDocument()->getReferenceMap()); }, - ) - ->addEventListener( - DocumentParsedEvent::class, - new Listener(), ); } } diff --git a/packages/documentator/src/Markdown/Extensions/Locator/Extension.php b/packages/documentator/src/Markdown/Extensions/Locator/Extension.php new file mode 100644 index 00000000..6eddfa68 --- /dev/null +++ b/packages/documentator/src/Markdown/Extensions/Locator/Extension.php @@ -0,0 +1,31 @@ +addInlineParser(new Parser(new CloseBracketParser()), 100) + ->addInlineParser(new Parser(new BacktickParser()), 200) + ->addEventListener( + DocumentParsedEvent::class, + new Listener(), + ); + + if ($environment->getConfiguration()->exists('footnote')) { + $environment->addInlineParser(new Parser(new FootnoteRefParser()), 100); + } + } +} diff --git a/packages/documentator/src/Markdown/Extensions/Locator/ParserTest.php b/packages/documentator/src/Markdown/Extensions/Locator/ExtensionTest.php similarity index 94% rename from packages/documentator/src/Markdown/Extensions/Locator/ParserTest.php rename to packages/documentator/src/Markdown/Extensions/Locator/ExtensionTest.php index 982cf970..7f9ff44a 100644 --- a/packages/documentator/src/Markdown/Extensions/Locator/ParserTest.php +++ b/packages/documentator/src/Markdown/Extensions/Locator/ExtensionTest.php @@ -2,7 +2,6 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Locator; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extension; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Core\Extension as CoreExtension; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block as ReferenceNode; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Renderer as ReferenceRenderer; @@ -14,6 +13,7 @@ use League\CommonMark\Extension\CommonMark\Renderer\Inline\CodeRenderer; use League\CommonMark\Extension\CommonMark\Renderer\Inline\ImageRenderer; use League\CommonMark\Extension\CommonMark\Renderer\Inline\LinkRenderer; +use League\CommonMark\Extension\Footnote\FootnoteExtension; use League\CommonMark\Extension\Footnote\Node\Footnote; use League\CommonMark\Extension\Footnote\Node\FootnoteRef; use League\CommonMark\Extension\Footnote\Renderer\FootnoteRefRenderer; @@ -32,13 +32,15 @@ /** * @internal */ +#[CoversClass(Extension::class)] #[CoversClass(Parser::class)] -final class ParserTest extends TestCase { +final class ExtensionTest extends TestCase { public function testParse(): void { $converter = new GithubFlavoredMarkdownConverter(); $environment = $converter->getEnvironment() - ->addExtension(new Extension()) + ->addExtension(new FootnoteExtension()) ->addExtension(new CoreExtension()) + ->addExtension(new Extension()) ->addRenderer(Link::class, new RendererWrapper(new LinkRenderer())) ->addRenderer(Image::class, new RendererWrapper(new ImageRenderer())) ->addRenderer(Footnote::class, new RendererWrapper(new FootnoteRenderer())) diff --git a/packages/documentator/src/Markdown/Extensions/Locator/ParserTest~document.md b/packages/documentator/src/Markdown/Extensions/Locator/ExtensionTest~document.md similarity index 100% rename from packages/documentator/src/Markdown/Extensions/Locator/ParserTest~document.md rename to packages/documentator/src/Markdown/Extensions/Locator/ExtensionTest~document.md diff --git a/packages/documentator/src/Markdown/Extensions/Locator/ParserTest~expected.xml b/packages/documentator/src/Markdown/Extensions/Locator/ExtensionTest~expected.xml similarity index 99% rename from packages/documentator/src/Markdown/Extensions/Locator/ParserTest~expected.xml rename to packages/documentator/src/Markdown/Extensions/Locator/ExtensionTest~expected.xml index 30ec5fbf..557fb602 100644 --- a/packages/documentator/src/Markdown/Extensions/Locator/ParserTest~expected.xml +++ b/packages/documentator/src/Markdown/Extensions/Locator/ExtensionTest~expected.xml @@ -60,7 +60,6 @@ - Lists diff --git a/packages/documentator/src/Markdown/Markdown.php b/packages/documentator/src/Markdown/Markdown.php index 85cebee7..4ca3e0f8 100644 --- a/packages/documentator/src/Markdown/Markdown.php +++ b/packages/documentator/src/Markdown/Markdown.php @@ -6,8 +6,10 @@ use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown as MarkdownContract; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Core\Extension as CoreExtension; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated\Extension as GeneratedExtension; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Locator\Extension as LocatorExtension; use League\CommonMark\Environment\Environment; use League\CommonMark\Environment\EnvironmentInterface; +use League\CommonMark\Extension\Footnote\FootnoteExtension; use League\CommonMark\GithubFlavoredMarkdownConverter; use League\CommonMark\Parser\MarkdownParser; use League\CommonMark\Parser\MarkdownParserInterface; @@ -25,8 +27,10 @@ public function __construct() { protected function initialize(): Environment { return (new GithubFlavoredMarkdownConverter())->getEnvironment() ->addExtension(new Extension()) + ->addExtension(new FootnoteExtension()) ->addExtension(new CoreExtension()) - ->addExtension(new GeneratedExtension()); + ->addExtension(new GeneratedExtension()) + ->addExtension(new LocatorExtension()); } #[Override] From 2be760ac478b6fc1fb5ec345806c827f120948e8 Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Tue, 10 Dec 2024 13:10:00 +0400 Subject: [PATCH 09/16] Extracted `\LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Extension`. --- .../{ => Extensions/Reference}/Extension.php | 12 +++--------- .../Reference/{ParserTest.php => ExtensionTest.php} | 4 ++-- ...serTest~document.md => ExtensionTest~document.md} | 0 ...rTest~expected.xml => ExtensionTest~expected.xml} | 0 packages/documentator/src/Markdown/Markdown.php | 5 +++-- .../src/Processor/Tasks/CodeLinks/TaskTest.php | 2 +- 6 files changed, 9 insertions(+), 14 deletions(-) rename packages/documentator/src/Markdown/{ => Extensions/Reference}/Extension.php (74%) rename packages/documentator/src/Markdown/Extensions/Reference/{ParserTest.php => ExtensionTest.php} (95%) rename packages/documentator/src/Markdown/Extensions/Reference/{ParserTest~document.md => ExtensionTest~document.md} (100%) rename packages/documentator/src/Markdown/Extensions/Reference/{ParserTest~expected.xml => ExtensionTest~expected.xml} (100%) diff --git a/packages/documentator/src/Markdown/Extension.php b/packages/documentator/src/Markdown/Extensions/Reference/Extension.php similarity index 74% rename from packages/documentator/src/Markdown/Extension.php rename to packages/documentator/src/Markdown/Extensions/Reference/Extension.php index 23ab56e5..bf5d97db 100644 --- a/packages/documentator/src/Markdown/Extension.php +++ b/packages/documentator/src/Markdown/Extensions/Reference/Extension.php @@ -1,8 +1,7 @@ getEnvironment() diff --git a/packages/documentator/src/Markdown/Extensions/Reference/ParserTest~document.md b/packages/documentator/src/Markdown/Extensions/Reference/ExtensionTest~document.md similarity index 100% rename from packages/documentator/src/Markdown/Extensions/Reference/ParserTest~document.md rename to packages/documentator/src/Markdown/Extensions/Reference/ExtensionTest~document.md diff --git a/packages/documentator/src/Markdown/Extensions/Reference/ParserTest~expected.xml b/packages/documentator/src/Markdown/Extensions/Reference/ExtensionTest~expected.xml similarity index 100% rename from packages/documentator/src/Markdown/Extensions/Reference/ParserTest~expected.xml rename to packages/documentator/src/Markdown/Extensions/Reference/ExtensionTest~expected.xml diff --git a/packages/documentator/src/Markdown/Markdown.php b/packages/documentator/src/Markdown/Markdown.php index 4ca3e0f8..c622bfac 100644 --- a/packages/documentator/src/Markdown/Markdown.php +++ b/packages/documentator/src/Markdown/Markdown.php @@ -7,6 +7,7 @@ use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Core\Extension as CoreExtension; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated\Extension as GeneratedExtension; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Locator\Extension as LocatorExtension; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Extension as ReferenceExtension; use League\CommonMark\Environment\Environment; use League\CommonMark\Environment\EnvironmentInterface; use League\CommonMark\Extension\Footnote\FootnoteExtension; @@ -26,11 +27,11 @@ public function __construct() { protected function initialize(): Environment { return (new GithubFlavoredMarkdownConverter())->getEnvironment() - ->addExtension(new Extension()) ->addExtension(new FootnoteExtension()) ->addExtension(new CoreExtension()) ->addExtension(new GeneratedExtension()) - ->addExtension(new LocatorExtension()); + ->addExtension(new LocatorExtension()) + ->addExtension(new ReferenceExtension()); } #[Override] diff --git a/packages/documentator/src/Processor/Tasks/CodeLinks/TaskTest.php b/packages/documentator/src/Processor/Tasks/CodeLinks/TaskTest.php index 4c175c53..a404a88c 100644 --- a/packages/documentator/src/Processor/Tasks/CodeLinks/TaskTest.php +++ b/packages/documentator/src/Processor/Tasks/CodeLinks/TaskTest.php @@ -7,10 +7,10 @@ use LastDragon_ru\LaraASP\Core\Path\FilePath; use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown as MarkdownContract; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extension; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated\Block as GeneratedNode; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated\Renderer as GeneratedNodeRenderer; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block as ReferenceNode; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Extension; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Renderer as ReferenceNodeRenderer; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\RendererWrapper; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory; From fef80dd2a6daa5c1825eb35576cafd0720af2d32 Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:04:06 +0400 Subject: [PATCH 10/16] Tests will use new `\LastDragon_ru\LaraASP\Documentator\Testing\Package\DocumentRenderer`. --- .../Extensions/Generated/ExtensionTest.php | 32 +- .../Generated/ExtensionTest~document.xml | 474 ++ .../Generated/ExtensionTest~expected.xml | 55 - .../Extensions/Generated/Renderer.php | 37 - .../Extensions/Locator/ExtensionTest.php | 62 +- .../Locator/ExtensionTest~document.xml | 4822 +++++++++++++++++ .../Locator/ExtensionTest~expected.xml | 414 -- .../Extensions/Reference/ExtensionTest.php | 35 +- .../Reference/ExtensionTest~document.xml | 224 + .../Reference/ExtensionTest~expected.xml | 103 - .../Extensions/Reference/Renderer.php | 43 - .../Markdown/Extensions/RendererWrapper.php | 128 - .../src/Markdown/Extensions/XmlRenderer.php | 18 - .../src/Markdown/MarkdownTest.php | 2 +- ...expected.xml => MarkdownTest~document.xml} | 0 .../Processor/Tasks/CodeLinks/TaskTest.php | 1022 +++- 16 files changed, 6523 insertions(+), 948 deletions(-) create mode 100644 packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest~document.xml delete mode 100644 packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest~expected.xml delete mode 100644 packages/documentator/src/Markdown/Extensions/Generated/Renderer.php create mode 100644 packages/documentator/src/Markdown/Extensions/Locator/ExtensionTest~document.xml delete mode 100644 packages/documentator/src/Markdown/Extensions/Locator/ExtensionTest~expected.xml create mode 100644 packages/documentator/src/Markdown/Extensions/Reference/ExtensionTest~document.xml delete mode 100644 packages/documentator/src/Markdown/Extensions/Reference/ExtensionTest~expected.xml delete mode 100644 packages/documentator/src/Markdown/Extensions/Reference/Renderer.php delete mode 100644 packages/documentator/src/Markdown/Extensions/RendererWrapper.php delete mode 100644 packages/documentator/src/Markdown/Extensions/XmlRenderer.php rename packages/documentator/src/Markdown/{MarkdownTest~expected.xml => MarkdownTest~document.xml} (100%) diff --git a/packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest.php b/packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest.php index 02783705..31a2bed7 100644 --- a/packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest.php +++ b/packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest.php @@ -2,11 +2,12 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\RendererWrapper; +use LastDragon_ru\LaraASP\Documentator\Markdown\Markdown; +use LastDragon_ru\LaraASP\Documentator\Testing\Package\DocumentRenderer; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; +use League\CommonMark\Environment\Environment; use League\CommonMark\GithubFlavoredMarkdownConverter; -use League\CommonMark\Parser\MarkdownParser; -use League\CommonMark\Xml\XmlRenderer; +use Override; use PHPUnit\Framework\Attributes\CoversClass; /** @@ -17,18 +18,23 @@ #[CoversClass(ParserContinue::class)] final class ExtensionTest extends TestCase { public function testParse(): void { - $converter = new GithubFlavoredMarkdownConverter(); - $environment = $converter->getEnvironment() - ->addExtension(new Extension()) - ->addRenderer(Block::class, new RendererWrapper(new Renderer())); + $markdown = new class() extends Markdown { + #[Override] + protected function initialize(): Environment { + $converter = new GithubFlavoredMarkdownConverter(); + $environment = $converter->getEnvironment() + ->addExtension(new Extension()); - $parser = new MarkdownParser($environment); - $document = $parser->parse(self::getTestData()->content('~document.md')); - $renderer = new XmlRenderer($environment); + return $environment; + } + }; - self::assertXmlStringEqualsXmlString( - self::getTestData()->content('~expected.xml'), - $renderer->renderDocument($document)->getContent(), + $renderer = $this->app()->make(DocumentRenderer::class); + $document = $markdown->parse(self::getTestData()->content('~document.md')); + + self::assertEquals( + self::getTestData()->content('~document.xml'), + $renderer->render($document), ); } } diff --git a/packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest~document.xml b/packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest~document.xml new file mode 100644 index 00000000..c76d15fa --- /dev/null +++ b/packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest~document.xml @@ -0,0 +1,474 @@ + + + + + + + + + + + + + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + 26 + + + + + + + + + 0 + + + 25 + + + 0 + + + + + + + 14 + + + + + + + + + 0 + + + 13 + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + 29 + + + + + + + + + 0 + + + 29 + + + 2 + + + + + + + 27 + + + + + + + + + 0 + + + 27 + + + 2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + 40 + + + + + + + + + 0 + + + 39 + + + 0 + + + + + + + 32 + + + + + + + + + 0 + + + 31 + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + 42 + + + + + + + + + 0 + + + 41 + + + 0 + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest~expected.xml b/packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest~expected.xml deleted file mode 100644 index 17ffac3c..00000000 --- a/packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest~expected.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - Generated - - - Text text text text text text text text text text text text text - - text text text text text text text text text text text text text - - text text text text text text text text text text text text. - - - ... nope ... - - - - Text text text text text text text text text text text text text - - text text text text text text text text text text text text text - - text text text text text text text text text text text text. - - - Nested should be ignored. - - - - - - should work - - - - - - - Text text text. - - - Nested should be ignored. - - - // - - : # (end: nested) - - - - - - Up to the end. - - - diff --git a/packages/documentator/src/Markdown/Extensions/Generated/Renderer.php b/packages/documentator/src/Markdown/Extensions/Generated/Renderer.php deleted file mode 100644 index 650df7fc..00000000 --- a/packages/documentator/src/Markdown/Extensions/Generated/Renderer.php +++ /dev/null @@ -1,37 +0,0 @@ - $node->id, - 'startMarkerLocation' => StartMarkerLocation::optional()->get($node), - 'endMarkerLocation' => EndMarkerLocation::optional()->get($node), - ]; - } -} diff --git a/packages/documentator/src/Markdown/Extensions/Locator/ExtensionTest.php b/packages/documentator/src/Markdown/Extensions/Locator/ExtensionTest.php index 7f9ff44a..946900d3 100644 --- a/packages/documentator/src/Markdown/Extensions/Locator/ExtensionTest.php +++ b/packages/documentator/src/Markdown/Extensions/Locator/ExtensionTest.php @@ -3,30 +3,13 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Locator; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Core\Extension as CoreExtension; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block as ReferenceNode; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Renderer as ReferenceRenderer; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\RendererWrapper; +use LastDragon_ru\LaraASP\Documentator\Markdown\Markdown; +use LastDragon_ru\LaraASP\Documentator\Testing\Package\DocumentRenderer; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; -use League\CommonMark\Extension\CommonMark\Node\Inline\Code; -use League\CommonMark\Extension\CommonMark\Node\Inline\Image; -use League\CommonMark\Extension\CommonMark\Node\Inline\Link; -use League\CommonMark\Extension\CommonMark\Renderer\Inline\CodeRenderer; -use League\CommonMark\Extension\CommonMark\Renderer\Inline\ImageRenderer; -use League\CommonMark\Extension\CommonMark\Renderer\Inline\LinkRenderer; +use League\CommonMark\Environment\Environment; use League\CommonMark\Extension\Footnote\FootnoteExtension; -use League\CommonMark\Extension\Footnote\Node\Footnote; -use League\CommonMark\Extension\Footnote\Node\FootnoteRef; -use League\CommonMark\Extension\Footnote\Renderer\FootnoteRefRenderer; -use League\CommonMark\Extension\Footnote\Renderer\FootnoteRenderer; -use League\CommonMark\Extension\Table\TableCell; -use League\CommonMark\Extension\Table\TableCellRenderer; -use League\CommonMark\Extension\Table\TableRow; -use League\CommonMark\Extension\Table\TableRowRenderer; -use League\CommonMark\Extension\Table\TableSection; -use League\CommonMark\Extension\Table\TableSectionRenderer; use League\CommonMark\GithubFlavoredMarkdownConverter; -use League\CommonMark\Parser\MarkdownParser; -use League\CommonMark\Xml\XmlRenderer; +use Override; use PHPUnit\Framework\Attributes\CoversClass; /** @@ -36,28 +19,25 @@ #[CoversClass(Parser::class)] final class ExtensionTest extends TestCase { public function testParse(): void { - $converter = new GithubFlavoredMarkdownConverter(); - $environment = $converter->getEnvironment() - ->addExtension(new FootnoteExtension()) - ->addExtension(new CoreExtension()) - ->addExtension(new Extension()) - ->addRenderer(Link::class, new RendererWrapper(new LinkRenderer())) - ->addRenderer(Image::class, new RendererWrapper(new ImageRenderer())) - ->addRenderer(Footnote::class, new RendererWrapper(new FootnoteRenderer())) - ->addRenderer(FootnoteRef::class, new RendererWrapper(new FootnoteRefRenderer())) - ->addRenderer(TableSection::class, new RendererWrapper(new TableSectionRenderer())) - ->addRenderer(TableRow::class, new RendererWrapper(new TableRowRenderer())) - ->addRenderer(TableCell::class, new RendererWrapper(new TableCellRenderer())) - ->addRenderer(ReferenceNode::class, new RendererWrapper(new ReferenceRenderer())) - ->addRenderer(Code::class, new RendererWrapper(new CodeRenderer())); + $markdown = new class() extends Markdown { + #[Override] + protected function initialize(): Environment { + $converter = new GithubFlavoredMarkdownConverter(); + $environment = $converter->getEnvironment() + ->addExtension(new FootnoteExtension()) + ->addExtension(new CoreExtension()) + ->addExtension(new Extension()); - $parser = new MarkdownParser($environment); - $document = $parser->parse(self::getTestData()->content('~document.md')); - $renderer = new XmlRenderer($environment); + return $environment; + } + }; - self::assertXmlStringEqualsXmlString( - self::getTestData()->content('~expected.xml'), - $renderer->renderDocument($document)->getContent(), + $renderer = $this->app()->make(DocumentRenderer::class); + $document = $markdown->parse(self::getTestData()->content('~document.md')); + + self::assertEquals( + self::getTestData()->content('~document.xml'), + $renderer->render($document), ); } } diff --git a/packages/documentator/src/Markdown/Extensions/Locator/ExtensionTest~document.xml b/packages/documentator/src/Markdown/Extensions/Locator/ExtensionTest~document.xml new file mode 100644 index 00000000..bdf5e11b --- /dev/null +++ b/packages/documentator/src/Markdown/Extensions/Locator/ExtensionTest~document.xml @@ -0,0 +1,4822 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Quote quote [link](https://example.com/).]]> + + + ]]> + + + Quote quote quote quote quote quote quote quote quote quote quote quote quote quote quote quote quote]]> + + + quote quote [link](https://example.com/) quote.]]> + + + + + + > Quote quote [link](https://example.com/).]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + | Header | Header |]]> + + + |--------------------------------------------------|--------|]]> + + + | Cell `\|` \\| [link](https://example.com/ "\\|") | Cell |]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ![image](https://example.com/)]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Text text[^quote]]]> + + + ]]> + + + [^quote]: Footnote text text text text text [link](https://example.com/)]]> + + + text text text text text [link](https://example.com/).]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Text `code` text.]]> + + + ]]> + + + > `code`]]> + + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + ]]> + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + + + + + + 36 + + + 13 + + + 5 + + + 0 + + + + + 14 + + + + + + + + + + + + + + + + + + + + + + + 5 + + + + + + 6 + + + 17 + + + 5 + + + 0 + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + + + + + + 33 + + + 58 + + + 5 + + + 0 + + + + + 11 + + + + + + + + + true + + + + + + + + + + + + + 5 + + + + + + 6 + + + 62 + + + 5 + + + 0 + + + + + 1 + + + + + + + + + + + + + + + + + + + + + 0 + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + 7 + + + + + + 28 + + + 10 + + + 7 + + + 0 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + 7 + + + + + + 4 + + + 38 + + + 7 + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 7 + + + + + + 36 + + + 48 + + + 7 + + + 0 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 7 + + + + + + 4 + + + 89 + + + 7 + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 8 + + + + + + 12 + + + 20 + + + 8 + + + 0 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 8 + + + + + + 28 + + + 43 + + + 8 + + + 0 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 10 + + + + + + 28 + + + 11 + + + 10 + + + 0 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + 10 + + + + + + 7 + + + 40 + + + 10 + + + 0 + + + + + + + + + + + + + + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + + + + + + + + + + + + + + + + + + + + + + + 16 + + + + + + 28 + + + 10 + + + 16 + + + 2 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + 17 + + + + + + 28 + + + 10 + + + 17 + + + 4 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + 18 + + + + + + 34 + + + 10 + + + 18 + + + 4 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + + + + + + + + + + + + + + + + + + + + + + + 22 + + + + + + 28 + + + 12 + + + 22 + + + 2 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 25 + + + + + + 28 + + + 12 + + + 25 + + + 2 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + 27 + + + + + + 28 + + + 12 + + + 27 + + + 4 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + 25 + + + 1 + + + 1 + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 75 + + + 27 + + + 2 + + + + + + + + + + + + + + + + + + + + + + + + + + + 31 + + + + + + 28 + + + 35 + + + 31 + + + 2 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + 25 + + + 1 + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 33 + + + + + + 12 + + + 6 + + + 33 + + + 1 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 75 + + + 27 + + + 1 + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + 25 + + + 1 + + + 1 + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 75 + + + 27 + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 34 + + + + + + 28 + + + 37 + + + 34 + + + 1 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 34 + + + + + + 28 + + + 71 + + + 34 + + + 1 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + + + + + 2 + + + + + + + + + + + + + + 2 + + + 50 + + + 1 + + + 1 + + + + + + + + + + + + + + + + + + + + + + + 2 + + + 8 + + + 52 + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + + + + + 2 + + + + + + + + + + + + + + 2 + + + 50 + + + 1 + + + 1 + + + + + + + + + + + + + + + + + + + 38 + + + + + + 4 + + + 6 + + + 38 + + + 3 + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 38 + + + + + + 34 + + + 15 + + + 38 + + + 3 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + 8 + + + 52 + + + 1 + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + 42 + + + + + + 30 + + + 10 + + + 42 + + + 0 + + + + + 8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 42 + + + + + + 38 + + + 46 + + + 42 + + + 0 + + + + + 8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 43 + + + + + + 14 + + + 10 + + + 43 + + + 0 + + + + + 8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 43 + + + + + + 30 + + + 35 + + + 43 + + + 0 + + + + + 8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 45 + + + + + + 30 + + + 11 + + + 45 + + + 0 + + + + + 8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + 47 + + + + + + 30 + + + 0 + + + 47 + + + 0 + + + + + 8 + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + 49 + + + + + + 14 + + + 0 + + + 49 + + + 0 + + + + + 8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + + + + + + + + + + + + + + + 51 + + + + + + 30 + + + 0 + + + 51 + + + 2 + + + + + 8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + 32 + + + 1 + + + 1 + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 8 + + + 34 + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + 32 + + + 1 + + + 1 + + + + + + + + + + + + + + + + + + + 55 + + + + + + 30 + + + 1 + + + 55 + + + 1 + + + + + 8 + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 8 + + + 34 + + + 1 + + + + + + + + + + + + + + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + + + + + + + + + + + + + + + + + + + + 64 + + + + + + 8 + + + 9 + + + 64 + + + 2 + + + + + + + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 0 + + + + + + + + + + + + + + + + + + + 76 + + + + + + 6 + + + 5 + + + 76 + + + 0 + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 76 + + + + + + 6 + + + 24 + + + 76 + + + 0 + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + 76 + + + + + + 6 + + + 53 + + + 76 + + + 0 + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 77 + + + + + + 6 + + + 5 + + + 77 + + + 0 + + + + + 1 + + + + + + + + + + + + + + + + + + + + + 77 + + + + + + 6 + + + 12 + + + 77 + + + 0 + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 77 + + + + + + 6 + + + 20 + + + 77 + + + 0 + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 77 + + + + + + 14 + + + 28 + + + 77 + + + 0 + + + + + 8 + + + + + + + + + + + + + + + + + + + + + + + + 77 + + + + + + 6 + + + 29 + + + 77 + + + 0 + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + 77 + + + + + + 14 + + + 43 + + + 77 + + + 0 + + + + + 1 + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + 81 + + + + + + 1 + + + 5 + + + 79 + + + 0 + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + + + + + + + + + + + + + + + 83 + + + + + + 6 + + + 5 + + + 83 + + + 2 + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + 4 + + + + + + + + + + + 85 + + + + + + 6 + + + 0 + + + 85 + + + 4 + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + 8 + + + 1 + + + 1 + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 13 + + + 10 + + + 1 + + + + + + + + + + + 87 + + + + + + 8 + + + 10 + + + 87 + + + 1 + + + + + 1 + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + 0 + + + + + + + + + + + + + + 0 + + + 8 + + + 1 + + + 1 + + + + + + + + + + + 89 + + + + + + 6 + + + 1 + + + 89 + + + 1 + + + + + 1 + + + + + + + + + + + + + + + + + 0 + + + 13 + + + 10 + + + 1 + + + + + + + + + + + + + + + + + + + 89 + + + + + + 6 + + + 15 + + + 89 + + + 1 + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 4 + + + + + + + + + 9 + + + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + 61 + + + + + + 28 + + + 34 + + + 61 + + + 9 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + 61 + + + + + + 4 + + + 62 + + + 61 + + + 9 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 62 + + + + + + 28 + + + 15 + + + 62 + + + 4 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + 4 + + + + + + + + + 12 + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + 66 + + + + + + 28 + + + 34 + + + 66 + + + 12 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 67 + + + + + + 28 + + + 25 + + + 67 + + + 6 + + + + + 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 4 + + + + + + + + + 11 + + + + + + + + + + + + + + + + + + + + + + + + 69 + + + + + + 9 + + + 44 + + + 69 + + + 11 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/documentator/src/Markdown/Extensions/Locator/ExtensionTest~expected.xml b/packages/documentator/src/Markdown/Extensions/Locator/ExtensionTest~expected.xml deleted file mode 100644 index 557fb602..00000000 --- a/packages/documentator/src/Markdown/Extensions/Locator/ExtensionTest~expected.xml +++ /dev/null @@ -1,414 +0,0 @@ - - - - Simple - - <!-- markdownlint-disable --> - - - - - - - - link - - - - - - - - **_ - link - - . - - - - - link - - - - - link - - - - - - - link - - - - link - - - - text text text text text text text text text text - [^2] - - - - - - link - - - - - - - Lists - - - - - - - link - - . - - - - - - - link - - . - - - - - - - link - - . - - - - - - - Quotes - - - - - - link - - . - - - Quote quote quote quote quote quote quote quote quote quote quote quote quote quote quote quote quote - - - - link - - - - - - - - - - link - - . - - - - - Tables - - - - - - Header - - - Header ( - - link - - ) - - - - - - - - - link - - - - - Cell - - - - - Cell - - - - - link - - - - link - - . - - - -
- - - - - - Header - - - Header - - - - - - - - | - - - link - - - - Cell - - - -
-
- - Images - - - - - image - - - - image - - - - - image - - - - image - - - - text text text text text text text text text text text text text text text text text - - - - - image - - - - - - - image - - - - - image - - - - - - image - - - - - - - - Header - - - Header - - - - - - - - image - - - - Cell - - - -
- - Footnotes - - - - Text text - - - - - Inline code - - - Text - code - - - code - - - code - - - - code - - code - - - code - - - - code - - - [code][link] - - - - - code - - - - - - code - - - - - code - - - - - - - - Header - - - Header - - - - - - - code - - - - code - - - -
- - - - Footnote text text text text - - - - - - - - - - link - - - - - - - link - - - - - - - - - - link - - - - - link - - . - - - - - - Text text text text text text text text text - - - - Text text text text text text text text text text text text - - text text text text text text text text text text text text. - - - - -
diff --git a/packages/documentator/src/Markdown/Extensions/Reference/ExtensionTest.php b/packages/documentator/src/Markdown/Extensions/Reference/ExtensionTest.php index f7c84a9f..58102021 100644 --- a/packages/documentator/src/Markdown/Extensions/Reference/ExtensionTest.php +++ b/packages/documentator/src/Markdown/Extensions/Reference/ExtensionTest.php @@ -2,11 +2,12 @@ namespace LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\RendererWrapper; +use LastDragon_ru\LaraASP\Documentator\Markdown\Markdown; +use LastDragon_ru\LaraASP\Documentator\Testing\Package\DocumentRenderer; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; +use League\CommonMark\Environment\Environment; use League\CommonMark\GithubFlavoredMarkdownConverter; -use League\CommonMark\Parser\MarkdownParser; -use League\CommonMark\Xml\XmlRenderer; +use Override; use PHPUnit\Framework\Attributes\CoversClass; /** @@ -16,20 +17,24 @@ #[CoversClass(Parser::class)] #[CoversClass(ParserStart::class)] #[CoversClass(ParserContinue::class)] -#[CoversClass(Renderer::class)] final class ExtensionTest extends TestCase { public function testParse(): void { - $converter = new GithubFlavoredMarkdownConverter(); - $environment = $converter->getEnvironment() - ->addExtension(new Extension()) - ->addRenderer(Block::class, new RendererWrapper(new Renderer())); + $markdown = new class() extends Markdown { + #[Override] + protected function initialize(): Environment { + $converter = new GithubFlavoredMarkdownConverter(); + $environment = $converter->getEnvironment() + ->addExtension(new Extension()); - $parser = new MarkdownParser($environment); - $document = $parser->parse(self::getTestData()->content('~document.md')); - $renderer = new XmlRenderer($environment); + return $environment; + } + }; + + $renderer = $this->app()->make(DocumentRenderer::class); + $document = $markdown->parse(self::getTestData()->content('~document.md')); $references = []; - foreach ($document->getReferenceMap() as $label => $reference) { + foreach ($document->node->getReferenceMap() as $label => $reference) { $references[$label] = $reference->getLabel(); } @@ -49,9 +54,9 @@ public function testParse(): void { ], $references, ); - self::assertXmlStringEqualsXmlString( - self::getTestData()->content('~expected.xml'), - $renderer->renderDocument($document)->getContent(), + self::assertEquals( + self::getTestData()->content('~document.xml'), + $renderer->render($document), ); } } diff --git a/packages/documentator/src/Markdown/Extensions/Reference/ExtensionTest~document.xml b/packages/documentator/src/Markdown/Extensions/Reference/ExtensionTest~document.xml new file mode 100644 index 00000000..b46361e5 --- /dev/null +++ b/packages/documentator/src/Markdown/Extensions/Reference/ExtensionTest~document.xml @@ -0,0 +1,224 @@ + + + + + + + + + + + + + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + ]]> + + + + + + + + 0 + + + + + + + + + + 0 + + + + + + + + + + 0 + + + + + + + + + + 0 + + + + + + + + + + 0 + + + + + + + + + + 0 + + + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + 0 + + + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + + + + + + 2 + + + + + + + + + + + + + + + + + + + + + + + 4 + + + + + + + + + + 4 + + + + + + + diff --git a/packages/documentator/src/Markdown/Extensions/Reference/ExtensionTest~expected.xml b/packages/documentator/src/Markdown/Extensions/Reference/ExtensionTest~expected.xml deleted file mode 100644 index 02546b5c..00000000 --- a/packages/documentator/src/Markdown/Extensions/Reference/ExtensionTest~expected.xml +++ /dev/null @@ -1,103 +0,0 @@ - - - - Simple - - <!-- markdownlint-disable --> - - - - - - - - Multiline - - - - - Inside Quote - - - - - - - - - - - - diff --git a/packages/documentator/src/Markdown/Extensions/Reference/Renderer.php b/packages/documentator/src/Markdown/Extensions/Reference/Renderer.php deleted file mode 100644 index 3d9c3334..00000000 --- a/packages/documentator/src/Markdown/Extensions/Reference/Renderer.php +++ /dev/null @@ -1,43 +0,0 @@ - $node->getLabel(), - 'destination' => $node->getDestination(), - 'title' => $node->getTitle(), - ]; - } -} diff --git a/packages/documentator/src/Markdown/Extensions/RendererWrapper.php b/packages/documentator/src/Markdown/Extensions/RendererWrapper.php deleted file mode 100644 index c6b191eb..00000000 --- a/packages/documentator/src/Markdown/Extensions/RendererWrapper.php +++ /dev/null @@ -1,128 +0,0 @@ -renderer; - } - - #[Override] - public function render(Node $node, ChildNodeRendererInterface $childRenderer): Stringable|string|null { - return $this->renderer instanceof NodeRendererInterface - ? $this->renderer->render($node, $childRenderer) - : ''; - } - - #[Override] - public function getXmlTagName(Node $node): string { - return $this->renderer instanceof XmlNodeRendererInterface || $this->renderer instanceof XmlRenderer - ? $this->renderer->getXmlTagName($node) - : ''; - } - - /** - * @inheritDoc - */ - #[Override] - public function getXmlAttributes(Node $node): array { - // Attributes - $additional = $this->getXmlAdditionalAttributes($node); - $attributes = $this->renderer instanceof XmlNodeRendererInterface || $this->renderer instanceof XmlRenderer - ? $this->renderer->getXmlAttributes($node) - : []; - $attributes = array_merge($attributes, $additional); - $attributes = array_map( - function (mixed $value): mixed { - if ($value instanceof Location) { - $value = $this->location($value); - } elseif (is_string($value)) { - $value = $this->escape($value); - } else { - // as is - } - - return $value; - }, - $attributes, - ); - - // Nulls are not allowed - $attributes = array_filter($attributes, static fn ($v) => $v !== null); - - // Return - return $attributes; - } - - protected function escape(string $string): string { - return preg_replace('/\R/u', '\\n', $string) ?? $string; - } - - protected function location(?Location $location): ?string { - $lines = []; - - foreach ($location ?? [] as $line) { - $lines[] = '{'.implode(',', [$line->line, $line->offset, $line->length ?? 'null']).'}'; - } - - return $lines !== [] ? '['.implode(',', $lines).']' : null; - } - - /** - * @return array - */ - private function getXmlAdditionalAttributes(Node $node): array { - $attributes = []; - $data = [ - 'location' => LocationData::class, - 'offset' => OffsetData::class, - 'length' => LengthData::class, - 'padding' => PaddingData::class, - 'blockPadding' => BlockPaddingData::class, - ]; - - foreach ($data as $key => $class) { - $attributes[$key] = $class::optional()->get($node); - } - - return $attributes; - } -} diff --git a/packages/documentator/src/Markdown/Extensions/XmlRenderer.php b/packages/documentator/src/Markdown/Extensions/XmlRenderer.php deleted file mode 100644 index 92acb98d..00000000 --- a/packages/documentator/src/Markdown/Extensions/XmlRenderer.php +++ /dev/null @@ -1,18 +0,0 @@ - - */ - public function getXmlAttributes(Node $node): array; -} diff --git a/packages/documentator/src/Markdown/MarkdownTest.php b/packages/documentator/src/Markdown/MarkdownTest.php index 98db15bd..a3ed9b57 100644 --- a/packages/documentator/src/Markdown/MarkdownTest.php +++ b/packages/documentator/src/Markdown/MarkdownTest.php @@ -20,7 +20,7 @@ public function testParse(): void { self::assertIsArray($lines); self::assertEquals( - self::getTestData()->content('~expected.xml'), + self::getTestData()->content('~document.xml'), $renderer->render($document), ); } diff --git a/packages/documentator/src/Markdown/MarkdownTest~expected.xml b/packages/documentator/src/Markdown/MarkdownTest~document.xml similarity index 100% rename from packages/documentator/src/Markdown/MarkdownTest~expected.xml rename to packages/documentator/src/Markdown/MarkdownTest~document.xml diff --git a/packages/documentator/src/Processor/Tasks/CodeLinks/TaskTest.php b/packages/documentator/src/Processor/Tasks/CodeLinks/TaskTest.php index a404a88c..e5d51780 100644 --- a/packages/documentator/src/Processor/Tasks/CodeLinks/TaskTest.php +++ b/packages/documentator/src/Processor/Tasks/CodeLinks/TaskTest.php @@ -7,12 +7,7 @@ use LastDragon_ru\LaraASP\Core\Path\FilePath; use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown as MarkdownContract; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated\Block as GeneratedNode; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated\Renderer as GeneratedNodeRenderer; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block as ReferenceNode; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Extension; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Renderer as ReferenceNodeRenderer; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\RendererWrapper; +use LastDragon_ru\LaraASP\Documentator\Markdown\Markdown as MarkdownImpl; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File; use LastDragon_ru\LaraASP\Documentator\Processor\Metadata\Composer; @@ -24,16 +19,12 @@ use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\CodeLinks\Links\ClassLink; use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\CodeLinks\Links\ClassMethodLink; use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\CodeLinks\Links\ClassPropertyLink; +use LastDragon_ru\LaraASP\Documentator\Testing\Package\DocumentRenderer; use LastDragon_ru\LaraASP\Documentator\Testing\Package\ProcessorHelper; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; -use League\CommonMark\Extension\CommonMark\Node\Inline\Code as CodeNode; -use League\CommonMark\Extension\CommonMark\Node\Inline\Link as LinkNode; -use League\CommonMark\Extension\CommonMark\Renderer\Inline\CodeRenderer as CodeNodeRenderer; -use League\CommonMark\Extension\CommonMark\Renderer\Inline\LinkRenderer as LinkNodeRenderer; -use League\CommonMark\GithubFlavoredMarkdownConverter; +use League\CommonMark\Environment\EnvironmentInterface; use League\CommonMark\Node\Block\Document as DocumentNode; use League\CommonMark\Node\Node; -use League\CommonMark\Xml\XmlRenderer; use Override; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; @@ -73,23 +64,29 @@ public function testInvoke(Closure|string $expected, string $document): void { } public function testParse(): void { - $converter = new GithubFlavoredMarkdownConverter(); - $environment = $converter->getEnvironment() - ->addExtension(new Extension()) - ->addRenderer(LinkNode::class, new RendererWrapper(new LinkNodeRenderer())) - ->addRenderer(CodeNode::class, new RendererWrapper(new CodeNodeRenderer())) - ->addRenderer(ReferenceNode::class, new RendererWrapper(new ReferenceNodeRenderer())) - ->addRenderer(GeneratedNode::class, new RendererWrapper(new GeneratedNodeRenderer())); - $renderer = new XmlRenderer($environment); - $render = static function (Node $node) use ($renderer): string { - $document = new DocumentNode(); + $markdown = new class() extends MarkdownImpl { + public function getEnvironment(): EnvironmentInterface { + return $this->environment; + } + }; + $renderer = $this->app()->make(DocumentRenderer::class); + $render = static function (Node $node) use ($markdown, $renderer): string { + return trim( + $renderer->render( + new class ($markdown, $node) extends Document { + public function __construct(MarkdownContract $markdown, Node $node) { + $document = new DocumentNode(); - $document->appendChild($node); + $document->appendChild($node); - return trim((string) $renderer->renderDocument($document)); + parent::__construct($markdown, $document, null); + } + }, + ), + ); }; - $document = $this->app()->make(MarkdownContract::class)->parse( + $document = $markdown->parse( <<<'MARKDOWN' Text `💀App\Deprecated` text `App\ClassA` text [App\ClassB](https://example.com/) text [`\App\ClassC`](https://example.com/) text [`Class`](./class.php "App\ClassD") @@ -145,22 +142,180 @@ public function parse(Document $document): array { 'blocks' => [ <<<'XML' - - - - code-links section - - - + + + + + + + + + + + + + + + + + + + 0 + + + + + 8 + + + + + + + + + 0 + + + 7 + + + 0 + + + + + + + 5 + + + + + + + + + 0 + + + 5 + + + 0 + + + + + + + + + + + + + + + + + + + + + + XML, <<<'XML' - - - - - - + + + + + + + + + + + + + + + + + + + 0 + + + + + 16 + + + + + + + + + 0 + + + 16 + + + 0 + + + + + + + 13 + + + + + + + + + 0 + + + 13 + + + 0 + + + + + + + + + + + 0 + + + + + + + + + + 0 + + + + + + XML, ], 'links' => [ @@ -170,9 +325,53 @@ public function parse(Document $document): array { 'nodes' => [ <<<'XML' - - 💀App\Deprecated - + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + 17 + + + 5 + + + 1 + + + 0 + + + + + 1 + + + + + + XML, ], ], @@ -182,9 +381,53 @@ public function parse(Document $document): array { 'nodes' => [ <<<'XML' - - App\ClassA - + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + 12 + + + 28 + + + 1 + + + 0 + + + + + 1 + + + + + + XML, ], ], @@ -194,11 +437,93 @@ public function parse(Document $document): array { 'nodes' => [ <<<'XML' - - - \App\ClassC - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + + 37 + + + 5 + + + 2 + + + 0 + + + + + 15 + + + + + + + + + + + 2 + + + + + + 13 + + + 6 + + + 2 + + + 0 + + + + + 1 + + + + + + + XML, ], ], @@ -208,11 +533,93 @@ public function parse(Document $document): array { 'nodes' => [ <<<'XML' - - - Class - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + + 35 + + + 48 + + + 2 + + + 0 + + + + + 9 + + + + + + + + + + + 2 + + + + + + 7 + + + 49 + + + 2 + + + 0 + + + + + 1 + + + + + + + XML, ], ], @@ -222,19 +629,209 @@ public function parse(Document $document): array { 'nodes' => [ <<<'XML' - - - Class - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 3 + + + + + + 16 + + + 5 + + + 3 + + + 0 + + + + + 9 + + + + + + + + + + + + + + + + + + + + + + + + 3 + + + + + + 7 + + + 6 + + + 3 + + + 0 + + + + + 1 + + + + + + + XML, <<<'XML' - - - 💀Class - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 3 + + + + + + 17 + + + 27 + + + 3 + + + 0 + + + + + 10 + + + + + + + + + + + + + + + + + + + + + + + + 3 + + + + + + 8 + + + 28 + + + 3 + + + 0 + + + + + 1 + + + + + + + XML, ], ], @@ -244,9 +841,53 @@ public function parse(Document $document): array { 'nodes' => [ <<<'XML' - - 💀App\Deprecated::method() - + + + + + + + + + + + + + + + + + + + + + 9 + + + + + + 27 + + + 5 + + + 9 + + + 0 + + + + + 1 + + + + + + XML, ], ], @@ -256,9 +897,53 @@ public function parse(Document $document): array { 'nodes' => [ <<<'XML' - - App\ClassA::$property - + + + + + + + + + + + + + + + + + + + + + 9 + + + + + + 23 + + + 38 + + + 9 + + + 0 + + + + + 1 + + + + + + XML, ], ], @@ -268,11 +953,93 @@ public function parse(Document $document): array { 'nodes' => [ <<<'XML' - - - Class::Constant - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 10 + + + + + + 55 + + + 5 + + + 10 + + + 0 + + + + + 19 + + + + + + + + + + + 10 + + + + + + 17 + + + 6 + + + 10 + + + 0 + + + + + 1 + + + + + + + XML, ], ], @@ -282,11 +1049,106 @@ public function parse(Document $document): array { 'nodes' => [ <<<'XML' - - - Class::method() - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 11 + + + + + + 27 + + + 5 + + + 11 + + + 0 + + + + + 19 + + + + + + + + + + + + + + + + + + + + + + + + 11 + + + + + + 17 + + + 6 + + + 11 + + + 0 + + + + + 1 + + + + + + + XML, ], ], From d315c8b5281a1374447e42878357b34e0cb1731d Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:14:17 +0400 Subject: [PATCH 11/16] `\LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block` => `\LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Node`. --- .../Extensions/Generated/ExtensionTest~document.xml | 8 ++++---- .../Markdown/Extensions/Generated/{Block.php => Node.php} | 2 +- .../src/Markdown/Extensions/Generated/ParserContinue.php | 6 +++--- .../src/Markdown/Extensions/Generated/ParserStart.php | 2 +- .../documentator/src/Markdown/MarkdownTest~document.xml | 4 ++-- .../src/Markdown/Mutations/Generated/Unwrap.php | 4 ++-- .../documentator/src/Processor/Tasks/CodeLinks/Task.php | 2 +- .../src/Processor/Tasks/CodeLinks/TaskTest.php | 4 ++-- .../documentator/src/Processor/Tasks/Preprocess/Task.php | 2 +- .../documentator/src/Processor/Tasks/Preprocess/Utils.php | 2 +- 10 files changed, 18 insertions(+), 18 deletions(-) rename packages/documentator/src/Markdown/Extensions/Generated/{Block.php => Node.php} (97%) diff --git a/packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest~document.xml b/packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest~document.xml index c76d15fa..24d22b6b 100644 --- a/packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest~document.xml +++ b/packages/documentator/src/Markdown/Extensions/Generated/ExtensionTest~document.xml @@ -91,7 +91,7 @@ - + @@ -211,7 +211,7 @@ - + @@ -281,7 +281,7 @@ - + @@ -423,7 +423,7 @@ - + diff --git a/packages/documentator/src/Markdown/Extensions/Generated/Block.php b/packages/documentator/src/Markdown/Extensions/Generated/Node.php similarity index 97% rename from packages/documentator/src/Markdown/Extensions/Generated/Block.php rename to packages/documentator/src/Markdown/Extensions/Generated/Node.php index 267923b6..93cdc750 100644 --- a/packages/documentator/src/Markdown/Extensions/Generated/Block.php +++ b/packages/documentator/src/Markdown/Extensions/Generated/Node.php @@ -17,7 +17,7 @@ * [//]: # (end: ) * ``` */ -class Block extends AbstractBlock { +class Node extends AbstractBlock { public function __construct( /** * @var non-empty-string diff --git a/packages/documentator/src/Markdown/Extensions/Generated/ParserContinue.php b/packages/documentator/src/Markdown/Extensions/Generated/ParserContinue.php index 862c1938..f1082e52 100644 --- a/packages/documentator/src/Markdown/Extensions/Generated/ParserContinue.php +++ b/packages/documentator/src/Markdown/Extensions/Generated/ParserContinue.php @@ -20,8 +20,8 @@ * @internal */ class ParserContinue implements BlockContinueParserInterface { - private Block $block; - private bool $finished; + private Node $block; + private bool $finished; /** * @var list */ @@ -32,7 +32,7 @@ class ParserContinue implements BlockContinueParserInterface { * @param non-empty-string $id */ public function __construct(string $line, string $id, private int $padding) { - $this->block = new Block($id); + $this->block = new Node($id); $this->lines = [$line]; $this->finished = false; } diff --git a/packages/documentator/src/Markdown/Extensions/Generated/ParserStart.php b/packages/documentator/src/Markdown/Extensions/Generated/ParserStart.php index 550bf35b..c6c6816c 100644 --- a/packages/documentator/src/Markdown/Extensions/Generated/ParserStart.php +++ b/packages/documentator/src/Markdown/Extensions/Generated/ParserStart.php @@ -32,7 +32,7 @@ public function tryStart(Cursor $cursor, MarkdownParserStateInterface $parserSta return BlockStart::none(); } - if (Utils::getParent($parserState->getActiveBlockParser()->getBlock(), Block::class) !== null) { + if (Utils::getParent($parserState->getActiveBlockParser()->getBlock(), Node::class) !== null) { return BlockStart::none(); } diff --git a/packages/documentator/src/Markdown/MarkdownTest~document.xml b/packages/documentator/src/Markdown/MarkdownTest~document.xml index 6abf5b4d..063e8dd5 100644 --- a/packages/documentator/src/Markdown/MarkdownTest~document.xml +++ b/packages/documentator/src/Markdown/MarkdownTest~document.xml @@ -230,7 +230,7 @@ - + @@ -385,7 +385,7 @@ - + diff --git a/packages/documentator/src/Markdown/Mutations/Generated/Unwrap.php b/packages/documentator/src/Markdown/Mutations/Generated/Unwrap.php index fe40002e..ea69f1cd 100644 --- a/packages/documentator/src/Markdown/Mutations/Generated/Unwrap.php +++ b/packages/documentator/src/Markdown/Mutations/Generated/Unwrap.php @@ -4,9 +4,9 @@ use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Mutation; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated\Block; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated\Data\EndMarkerLocation; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated\Data\StartMarkerLocation; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated\Node; use League\CommonMark\Node\NodeIterator; use Override; @@ -29,7 +29,7 @@ public function __invoke(Document $document): iterable { // Process foreach ($document->node->iterator(NodeIterator::FLAG_BLOCKS_ONLY) as $node) { // Generated? - if (!($node instanceof Block)) { + if (!($node instanceof Node)) { continue; } diff --git a/packages/documentator/src/Processor/Tasks/CodeLinks/Task.php b/packages/documentator/src/Processor/Tasks/CodeLinks/Task.php index 9229eb11..1f944019 100644 --- a/packages/documentator/src/Processor/Tasks/CodeLinks/Task.php +++ b/packages/documentator/src/Processor/Tasks/CodeLinks/Task.php @@ -9,7 +9,7 @@ use LastDragon_ru\LaraASP\Documentator\Editor\Locations\Location; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Location as LocationData; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated\Block as GeneratedNode; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated\Node as GeneratedNode; use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Changeset; use LastDragon_ru\LaraASP\Documentator\Markdown\Utils; use LastDragon_ru\LaraASP\Documentator\Processor\Contracts\Dependency; diff --git a/packages/documentator/src/Processor/Tasks/CodeLinks/TaskTest.php b/packages/documentator/src/Processor/Tasks/CodeLinks/TaskTest.php index e5d51780..c9a85f62 100644 --- a/packages/documentator/src/Processor/Tasks/CodeLinks/TaskTest.php +++ b/packages/documentator/src/Processor/Tasks/CodeLinks/TaskTest.php @@ -154,7 +154,7 @@ public function parse(Document $document): array { - + @@ -240,7 +240,7 @@ public function parse(Document $document): array { - + diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Task.php b/packages/documentator/src/Processor/Tasks/Preprocess/Task.php index c97abd26..06ed36ec 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Task.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Task.php @@ -7,7 +7,7 @@ use LastDragon_ru\LaraASP\Core\Application\ContainerResolver; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Location; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated\Block as GeneratedNode; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated\Node as GeneratedNode; use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Changeset; use LastDragon_ru\LaraASP\Documentator\Processor\Contracts\Dependency; use LastDragon_ru\LaraASP\Documentator\Processor\Contracts\Task as TaskContract; diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Utils.php b/packages/documentator/src/Processor/Tasks/Preprocess/Utils.php index a9d8d9f2..a1f47732 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Utils.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Utils.php @@ -3,7 +3,7 @@ namespace LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated\Block as GeneratedNode; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated\Node as GeneratedNode; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block as ReferenceNode; use LastDragon_ru\LaraASP\Documentator\Markdown\Utils as MarkdownUtils; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File; From d16cd8c2c79a6d149a4b0e27e42bc0606ddf7e36 Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:25:18 +0400 Subject: [PATCH 12/16] `\LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block` => `\LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Node`. --- .../Reference/ExtensionTest~document.xml | 24 +++++++++---------- .../Reference/{Block.php => Node.php} | 2 +- .../Extensions/Reference/ParserContinue.php | 4 ++-- .../src/Markdown/MarkdownTest~document.xml | 10 ++++---- .../src/Markdown/Mutations/Document/Move.php | 2 +- .../Markdown/Mutations/Reference/Inline.php | 2 +- .../Markdown/Mutations/Reference/Prefix.php | 2 +- .../Processor/Tasks/CodeLinks/TaskTest.php | 4 ++-- .../Processor/Tasks/Preprocess/Context.php | 4 ++-- .../IncludeArtisan/InstructionTest.php | 8 +++---- .../IncludeDocBlock/InstructionTest.php | 4 ++-- .../IncludeDocumentList/Instruction.php | 6 ++--- .../IncludeDocumentList/InstructionTest.php | 6 ++--- .../IncludeExample/InstructionTest.php | 6 ++--- .../IncludeExec/InstructionTest.php | 4 ++-- .../IncludeFile/InstructionTest.php | 4 ++-- .../InstructionTest.php | 10 ++++---- .../IncludePackageList/InstructionTest.php | 8 +++---- .../IncludeTemplate/InstructionTest.php | 10 ++++---- .../src/Processor/Tasks/Preprocess/Token.php | 4 ++-- .../src/Processor/Tasks/Preprocess/Utils.php | 2 +- 21 files changed, 63 insertions(+), 63 deletions(-) rename packages/documentator/src/Markdown/Extensions/Reference/{Block.php => Node.php} (92%) diff --git a/packages/documentator/src/Markdown/Extensions/Reference/ExtensionTest~document.xml b/packages/documentator/src/Markdown/Extensions/Reference/ExtensionTest~document.xml index b46361e5..7d5da3f8 100644 --- a/packages/documentator/src/Markdown/Extensions/Reference/ExtensionTest~document.xml +++ b/packages/documentator/src/Markdown/Extensions/Reference/ExtensionTest~document.xml @@ -39,7 +39,7 @@ ]]> - + @@ -49,7 +49,7 @@ - + @@ -59,7 +59,7 @@ - + @@ -69,7 +69,7 @@ - + @@ -79,7 +79,7 @@ - + @@ -89,7 +89,7 @@ - + @@ -119,7 +119,7 @@ - + @@ -129,7 +129,7 @@ - + @@ -165,7 +165,7 @@ - + @@ -175,7 +175,7 @@ - + @@ -198,7 +198,7 @@ - + @@ -208,7 +208,7 @@ - + diff --git a/packages/documentator/src/Markdown/Extensions/Reference/Block.php b/packages/documentator/src/Markdown/Extensions/Reference/Node.php similarity index 92% rename from packages/documentator/src/Markdown/Extensions/Reference/Block.php rename to packages/documentator/src/Markdown/Extensions/Reference/Node.php index 1d3dec71..5e762c33 100644 --- a/packages/documentator/src/Markdown/Extensions/Reference/Block.php +++ b/packages/documentator/src/Markdown/Extensions/Reference/Node.php @@ -9,7 +9,7 @@ /** * @internal */ -class Block extends AbstractBlock implements ReferenceInterface { +class Node extends AbstractBlock implements ReferenceInterface { private ?ReferenceInterface $reference = null; public function setReference(?ReferenceInterface $reference): static { diff --git a/packages/documentator/src/Markdown/Extensions/Reference/ParserContinue.php b/packages/documentator/src/Markdown/Extensions/Reference/ParserContinue.php index 10b5cd6b..cabc761e 100644 --- a/packages/documentator/src/Markdown/Extensions/Reference/ParserContinue.php +++ b/packages/documentator/src/Markdown/Extensions/Reference/ParserContinue.php @@ -14,7 +14,7 @@ * @internal */ class ParserContinue implements BlockContinueParserInterface { - private Block $block; + private Node $block; private Parser $parser; private int $padding; private bool $finished; @@ -22,7 +22,7 @@ class ParserContinue implements BlockContinueParserInterface { public function __construct( private readonly ?ReferenceMapInterface $referenceMap, ) { - $this->block = new Block(); + $this->block = new Node(); $this->parser = new Parser(); $this->padding = 0; $this->finished = false; diff --git a/packages/documentator/src/Markdown/MarkdownTest~document.xml b/packages/documentator/src/Markdown/MarkdownTest~document.xml index 063e8dd5..882bcc0c 100644 --- a/packages/documentator/src/Markdown/MarkdownTest~document.xml +++ b/packages/documentator/src/Markdown/MarkdownTest~document.xml @@ -328,7 +328,7 @@ - + @@ -353,7 +353,7 @@ - + @@ -475,7 +475,7 @@ - + @@ -485,7 +485,7 @@ - + @@ -516,7 +516,7 @@ - + diff --git a/packages/documentator/src/Markdown/Mutations/Document/Move.php b/packages/documentator/src/Markdown/Mutations/Document/Move.php index dad76cb0..81704bbe 100644 --- a/packages/documentator/src/Markdown/Mutations/Document/Move.php +++ b/packages/documentator/src/Markdown/Mutations/Document/Move.php @@ -10,7 +10,7 @@ use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Offset; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Reference; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block as ReferenceNode; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Node as ReferenceNode; use LastDragon_ru\LaraASP\Documentator\Markdown\Utils; use League\CommonMark\Extension\CommonMark\Node\Inline\AbstractWebResource; use League\CommonMark\Extension\CommonMark\Node\Inline\Image; diff --git a/packages/documentator/src/Markdown/Mutations/Reference/Inline.php b/packages/documentator/src/Markdown/Mutations/Reference/Inline.php index 73730ac4..981a5d6b 100644 --- a/packages/documentator/src/Markdown/Mutations/Reference/Inline.php +++ b/packages/documentator/src/Markdown/Mutations/Reference/Inline.php @@ -8,7 +8,7 @@ use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Offset; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Reference; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block as ReferenceNode; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Node as ReferenceNode; use LastDragon_ru\LaraASP\Documentator\Markdown\Utils; use League\CommonMark\Extension\CommonMark\Node\Inline\AbstractWebResource; use League\CommonMark\Extension\CommonMark\Node\Inline\Image; diff --git a/packages/documentator/src/Markdown/Mutations/Reference/Prefix.php b/packages/documentator/src/Markdown/Mutations/Reference/Prefix.php index 665e04f0..eae21bbd 100644 --- a/packages/documentator/src/Markdown/Mutations/Reference/Prefix.php +++ b/packages/documentator/src/Markdown/Mutations/Reference/Prefix.php @@ -9,7 +9,7 @@ use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Offset as OffsetData; use LastDragon_ru\LaraASP\Documentator\Markdown\Data\Reference as ReferenceData; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block as ReferenceNode; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Node as ReferenceNode; use LastDragon_ru\LaraASP\Documentator\Markdown\Utils; use League\CommonMark\Extension\CommonMark\Node\Inline\AbstractWebResource; use League\CommonMark\Extension\CommonMark\Node\Inline\Image; diff --git a/packages/documentator/src/Processor/Tasks/CodeLinks/TaskTest.php b/packages/documentator/src/Processor/Tasks/CodeLinks/TaskTest.php index c9a85f62..6ef3b505 100644 --- a/packages/documentator/src/Processor/Tasks/CodeLinks/TaskTest.php +++ b/packages/documentator/src/Processor/Tasks/CodeLinks/TaskTest.php @@ -293,7 +293,7 @@ public function parse(Document $document): array {
- + @@ -303,7 +303,7 @@ public function parse(Document $document): array { - + diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Context.php b/packages/documentator/src/Processor/Tasks/Preprocess/Context.php index f035da35..4215337f 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Context.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Context.php @@ -5,7 +5,7 @@ use LastDragon_ru\LaraASP\Core\Path\FilePath; use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Mutation; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Node; use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Composite; use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Document\MakeInlinable; use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Document\MakeSplittable; @@ -19,7 +19,7 @@ public function __construct( public readonly Directory $root, public readonly File $file, public readonly Document $document, - public readonly Block $node, + public readonly Node $node, private readonly Mutation $mutation, ) { // empty diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeArtisan/InstructionTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeArtisan/InstructionTest.php index e52ee545..a5f87672 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeArtisan/InstructionTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeArtisan/InstructionTest.php @@ -7,7 +7,7 @@ use LastDragon_ru\LaraASP\Core\Path\DirectoryPath; use LastDragon_ru\LaraASP\Core\Path\FilePath; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Node; use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Nop; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File; @@ -35,7 +35,7 @@ public function testInvoke(): void { $params = new Parameters('...'); $expected = 'result'; $command = 'command to execute'; - $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Node(), new Nop()); $instance = $this->app()->make(Instruction::class); $this->override(Kernel::class, static function (MockInterface $mock) use ($command, $expected): void { @@ -77,7 +77,7 @@ static function (InputInterface $input, OutputInterface $output) use ($expected) public function testInvokeFailed(): void { $root = new Directory((new DirectoryPath(__DIR__))->getNormalizedPath(), false); $file = new File((new FilePath(__FILE__))->getNormalizedPath(), false); - $node = new class() extends Block { + $node = new class() extends Node { #[Override] public function getDestination(): string { return 'command to execute'; @@ -137,7 +137,7 @@ public function testGetCommand(): void { $file = new File((new FilePath(__FILE__))->getNormalizedPath(), false); $params = new Parameters('...'); $command = 'artisan:command $directory {$directory} "{$directory}" $file {$file} "{$file}"'; - $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Node(), new Nop()); $instance = new class (Mockery::mock(ApplicationResolver::class)) extends Instruction { #[Override] public function getCommand(Context $context, string $target, Parameters $parameters): string { diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocBlock/InstructionTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocBlock/InstructionTest.php index 0d22d1af..b10281ad 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocBlock/InstructionTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocBlock/InstructionTest.php @@ -6,7 +6,7 @@ use Exception; use LastDragon_ru\LaraASP\Core\Path\FilePath; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Node; use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Nop; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File; @@ -35,7 +35,7 @@ public function testInvoke(Closure|string $expected, string $file, Parameters $p $root = new Directory($path->getDirectoryPath(), false); $file = new File($path, false); $target = $file->getName(); - $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Node(), new Nop()); $instance = $this->app()->make(Instruction::class); if ($expected instanceof Closure) { diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocumentList/Instruction.php b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocumentList/Instruction.php index d0b8b679..caa82b31 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocumentList/Instruction.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocumentList/Instruction.php @@ -5,7 +5,7 @@ use Generator; use Iterator; use LastDragon_ru\LaraASP\Core\Utils\Cast; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Node; use LastDragon_ru\LaraASP\Documentator\PackageViewer; use LastDragon_ru\LaraASP\Documentator\Processor\Contracts\Dependency; use LastDragon_ru\LaraASP\Documentator\Processor\Dependencies\FileIterator; @@ -118,7 +118,7 @@ public function __invoke(Context $context, string $target, mixed $parameters): G /** * @return int<1,6> */ - private function getLevel(Block $node, Parameters $parameters): int { + private function getLevel(Node $node, Parameters $parameters): int { $level = match ($parameters->level) { 0 => $this->getNodeLevel($node), null => $this->getNodeLevel($node) + 1, @@ -130,7 +130,7 @@ private function getLevel(Block $node, Parameters $parameters): int { return $level; } - private function getNodeLevel(Block $block): int { + private function getNodeLevel(Node $block): int { $level = 0; do { diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocumentList/InstructionTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocumentList/InstructionTest.php index 771c4512..334d4b30 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocumentList/InstructionTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocumentList/InstructionTest.php @@ -4,7 +4,7 @@ use LastDragon_ru\LaraASP\Core\Path\FilePath; use LastDragon_ru\LaraASP\Documentator\Markdown\Contracts\Markdown; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Node; use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Nop; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File; @@ -33,9 +33,9 @@ public function testInvoke(string $expected, string $path, string $content): voi $root = new Directory($path->getDirectoryPath(), false); $file = new File($path, false); $document = $this->app()->make(Markdown::class)->parse($content, $path); - $instruction = (new Query())->where(Query::type(Block::class))->findOne($document->node); + $instruction = (new Query())->where(Query::type(Node::class))->findOne($document->node); - self::assertInstanceOf(Block::class, $instruction); + self::assertInstanceOf(Node::class, $instruction); // Parameters $target = $instruction->getDestination(); diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeExample/InstructionTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeExample/InstructionTest.php index cf6fc27d..fc0df9d9 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeExample/InstructionTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeExample/InstructionTest.php @@ -4,7 +4,7 @@ use LastDragon_ru\LaraASP\Core\Path\FilePath; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Node; use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Nop; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File; @@ -34,7 +34,7 @@ public function testInvoke(string $expected, string $output): void { $file = new File($path, false); $params = new Parameters('...'); $target = self::getTestData()->path('Example.md'); - $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Node(), new Nop()); $this->override(Runner::class, static function (MockInterface $mock) use ($target, $output): void { $mock @@ -60,7 +60,7 @@ public function testInvokeNoRun(): void { $file = new File($path, false); $params = new Parameters('...'); $target = $file->getName(); - $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Node(), new Nop()); $expected = trim($file->getContent()); $instance = $this->app()->make(Instruction::class); $actual = ProcessorHelper::runInstruction($instance, $context, $target, $params); diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeExec/InstructionTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeExec/InstructionTest.php index 73d8517e..e9d769f6 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeExec/InstructionTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeExec/InstructionTest.php @@ -7,7 +7,7 @@ use LastDragon_ru\LaraASP\Core\Path\DirectoryPath; use LastDragon_ru\LaraASP\Core\Path\FilePath; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Node; use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Nop; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File; @@ -28,7 +28,7 @@ public function testInvoke(): void { $params = new Parameters('...'); $expected = 'result'; $command = 'command to execute'; - $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Node(), new Nop()); $factory = $this->override(Factory::class, function () use ($command, $expected): Factory { $factory = $this->app()->make(Factory::class); $factory->preventStrayProcesses(); diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeFile/InstructionTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeFile/InstructionTest.php index 747ebcfc..cee712a3 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeFile/InstructionTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeFile/InstructionTest.php @@ -5,7 +5,7 @@ use LastDragon_ru\LaraASP\Core\Path\DirectoryPath; use LastDragon_ru\LaraASP\Core\Path\FilePath; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Node; use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Nop; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File; @@ -31,7 +31,7 @@ public function testInvoke(string $expected, string $source): void { $file = new File((new FilePath(__FILE__))->getNormalizedPath(), false); $params = new Parameters('...'); $target = self::getTestData()->path($source); - $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Node(), new Nop()); $instance = $this->app()->make(Instruction::class); $expected = self::getTestData()->content($expected); $actual = ProcessorHelper::runInstruction($instance, $context, $target, $params); diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeGraphqlDirective/InstructionTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeGraphqlDirective/InstructionTest.php index 49b2f158..2caabf06 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeGraphqlDirective/InstructionTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeGraphqlDirective/InstructionTest.php @@ -7,7 +7,7 @@ use LastDragon_ru\LaraASP\Core\Path\DirectoryPath; use LastDragon_ru\LaraASP\Core\Path\FilePath; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Node; use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Nop; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File; @@ -54,7 +54,7 @@ public function testInvoke(): void { $file = Mockery::mock(File::class); $params = new Parameters('...'); $target = '@test'; - $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Node(), new Nop()); $instance = $this->app()->make(Instruction::class); $actual = ProcessorHelper::runInstruction($instance, $context, $target, $params); @@ -81,7 +81,7 @@ public function testInvokeNoPrinter(): void { $file = new File((new FilePath(__FILE__))->getNormalizedPath(), false); $params = new Parameters('...'); $target = '@test'; - $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Node(), new Nop()); $instance = $this->app()->make(Instruction::class); self::expectExceptionObject( @@ -109,7 +109,7 @@ public function testInvokeNoDirective(): void { $file = new File((new FilePath(__FILE__))->getNormalizedPath(), false); $params = new Parameters('...'); $target = '@test'; - $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Node(), new Nop()); $instance = $this->app()->make(Instruction::class); self::expectExceptionObject( @@ -128,7 +128,7 @@ public function testInvokeNoDirectiveResolver(): void { $file = new File((new FilePath(__FILE__))->getNormalizedPath(), false); $params = new Parameters('...'); $target = '@test'; - $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Node(), new Nop()); $instance = $this->app()->make(Instruction::class); self::expectExceptionObject( diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludePackageList/InstructionTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludePackageList/InstructionTest.php index f1e77177..b4d4cceb 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludePackageList/InstructionTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludePackageList/InstructionTest.php @@ -4,7 +4,7 @@ use LastDragon_ru\LaraASP\Core\Path\FilePath; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Node; use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Nop; use LastDragon_ru\LaraASP\Documentator\Processor\Dependencies\FileReference; use LastDragon_ru\LaraASP\Documentator\Processor\Exceptions\DependencyNotFound; @@ -35,7 +35,7 @@ public function testInvoke(string $expected, string $template, SortOrder $order) $file = new File($path, false); $target = $root->getDirectoryPath('packages'); $params = new Parameters('...', template: $template, order: $order); - $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Node(), new Nop()); $instance = $this->app()->make(Instruction::class); $actual = ProcessorHelper::runInstruction($instance, $context, $target, $params); @@ -56,7 +56,7 @@ public function testInvokeNoReadme(): void { $file = new File($path, false); $target = $root->getDirectoryPath('no readme'); $params = new Parameters('...'); - $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Node(), new Nop()); $instance = $this->app()->make(Instruction::class); $package = $fs->getDirectory(new Directory($target, false), 'package'); @@ -75,7 +75,7 @@ public function testInvokeEmptyReadme(): void { $file = new File($path, false); $target = $root->getDirectoryPath('empty readme'); $params = new Parameters('...'); - $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Node(), new Nop()); $instance = $this->app()->make(Instruction::class); $package = $fs->getDirectory(new Directory($target, false), 'package'); $expected = $fs->getFile($root, 'empty readme/package/README.md'); diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeTemplate/InstructionTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeTemplate/InstructionTest.php index 96ca6d8d..3d72415b 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeTemplate/InstructionTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeTemplate/InstructionTest.php @@ -5,7 +5,7 @@ use LastDragon_ru\LaraASP\Core\Path\DirectoryPath; use LastDragon_ru\LaraASP\Core\Path\FilePath; use LastDragon_ru\LaraASP\Documentator\Markdown\Document; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Node; use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\Nop; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\Directory; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File; @@ -37,7 +37,7 @@ public function testInvoke(string $expected, string $source, array $data): void $file = new File((new FilePath(__FILE__))->getNormalizedPath(), false); $params = new Parameters('...', $data); $target = self::getTestData()->path($source); - $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Node(), new Nop()); $instance = $this->app()->make(Instruction::class); $expected = self::getTestData()->content($expected); $actual = ProcessorHelper::runInstruction($instance, $context, $target, $params); @@ -56,7 +56,7 @@ public function testInvokeNoData(): void { $file = new File((new FilePath(__FILE__))->getNormalizedPath(), false); $params = new Parameters('...', []); $target = $file->getPath(); - $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Node(), new Nop()); $instance = $this->app()->make(Instruction::class); self::expectExceptionObject( @@ -77,7 +77,7 @@ public function testInvokeVariablesUnused(): void { 'd' => 'D', ]); $target = $file->getPath(); - $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Node(), new Nop()); $instance = $this->app()->make(Instruction::class); self::expectExceptionObject( @@ -95,7 +95,7 @@ public function testInvokeVariablesMissed(): void { 'a' => 'A', ]); $target = $file->getPath(); - $context = new Context($root, $file, Mockery::mock(Document::class), new Block(), new Nop()); + $context = new Context($root, $file, Mockery::mock(Document::class), new Node(), new Nop()); $instance = $this->app()->make(Instruction::class); self::expectExceptionObject( diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Token.php b/packages/documentator/src/Processor/Tasks/Preprocess/Token.php index c4b853b4..f375e7c3 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Token.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Token.php @@ -2,7 +2,7 @@ namespace LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Node; use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Contracts\Instruction; use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Contracts\Parameters; @@ -24,7 +24,7 @@ public function __construct( */ public readonly mixed $parameters, /** - * @var non-empty-list + * @var non-empty-list */ public array $nodes, ) { diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Utils.php b/packages/documentator/src/Processor/Tasks/Preprocess/Utils.php index a1f47732..20e2095b 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Utils.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Utils.php @@ -4,7 +4,7 @@ use LastDragon_ru\LaraASP\Documentator\Markdown\Document; use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Generated\Node as GeneratedNode; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Block as ReferenceNode; +use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Node as ReferenceNode; use LastDragon_ru\LaraASP\Documentator\Markdown\Utils as MarkdownUtils; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File; use LastDragon_ru\LaraASP\Documentator\Processor\InstanceList; From 35f5a2cdc8474816bd57ce12d663e3d61c81bfaf Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:33:58 +0400 Subject: [PATCH 13/16] `\League\CommonMark\Node\Node` will be used instead of `\LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Node`. --- .../Preprocess/Instructions/IncludeDocumentList/Instruction.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocumentList/Instruction.php b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocumentList/Instruction.php index caa82b31..a904c5a9 100644 --- a/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocumentList/Instruction.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeDocumentList/Instruction.php @@ -5,7 +5,6 @@ use Generator; use Iterator; use LastDragon_ru\LaraASP\Core\Utils\Cast; -use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Reference\Node; use LastDragon_ru\LaraASP\Documentator\PackageViewer; use LastDragon_ru\LaraASP\Documentator\Processor\Contracts\Dependency; use LastDragon_ru\LaraASP\Documentator\Processor\Dependencies\FileIterator; @@ -18,6 +17,7 @@ use LastDragon_ru\LaraASP\Documentator\Utils\Sorter; use LastDragon_ru\LaraASP\Documentator\Utils\Text; use League\CommonMark\Extension\CommonMark\Node\Block\Heading; +use League\CommonMark\Node\Node; use Override; use function array_filter; From dae2af5e235a265badb80177805f5f7b31fb581d Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Tue, 10 Dec 2024 15:37:39 +0400 Subject: [PATCH 14/16] feat(documentator): Min version of `league/commonmark` set to `^2.6.0` (because of Delimiter Stack changes). --- composer.json | 2 +- packages/documentator/composer.json | 2 +- .../Markdown/Extensions/Locator/Parser.php | 24 ++++++++----------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index 6fda83c3..7ebf7354 100644 --- a/composer.json +++ b/composer.json @@ -62,7 +62,7 @@ "illuminate/translation": "^11.0.8", "illuminate/validation": "^11.0.8", "larastan/larastan": "^2.8.1", - "league/commonmark": "^2.5.1", + "league/commonmark": "^2.6.0", "league/config": "^1.1.1", "mockery/mockery": "^1.6.5", "nette/neon": "^3.4", diff --git a/packages/documentator/composer.json b/packages/documentator/composer.json index 63aac8d9..520185d1 100644 --- a/packages/documentator/composer.json +++ b/packages/documentator/composer.json @@ -27,7 +27,7 @@ "illuminate/console": "^11.0.8", "illuminate/process": "^11.0.8", "illuminate/support": "^11.0.8", - "league/commonmark": "^2.5.1", + "league/commonmark": "^2.6.0", "league/config": "^1.1.1", "nikic/php-parser": "^5.0", "phpstan/phpdoc-parser": "^1.25", diff --git a/packages/documentator/src/Markdown/Extensions/Locator/Parser.php b/packages/documentator/src/Markdown/Extensions/Locator/Parser.php index 55f8df95..d9ebbab2 100644 --- a/packages/documentator/src/Markdown/Extensions/Locator/Parser.php +++ b/packages/documentator/src/Markdown/Extensions/Locator/Parser.php @@ -10,13 +10,13 @@ use LastDragon_ru\LaraASP\Documentator\Markdown\Extensions\Aware; use LastDragon_ru\LaraASP\Documentator\Markdown\Utils; use LastDragon_ru\LaraASP\Documentator\Utils\Text; -use League\CommonMark\Delimiter\DelimiterInterface; use League\CommonMark\Environment\Environment; use League\CommonMark\Environment\EnvironmentAwareInterface; use League\CommonMark\Extension\CommonMark\Parser\Inline\CloseBracketParser; use League\CommonMark\Extension\Footnote\Node\FootnoteRef; use League\CommonMark\Extension\Table\TableCell; use League\CommonMark\Node\Node; +use League\CommonMark\Node\StringContainerInterface; use League\CommonMark\Parser\Inline\InlineParserInterface; use League\CommonMark\Parser\Inline\InlineParserMatch; use League\CommonMark\Parser\InlineParserContext; @@ -74,7 +74,7 @@ public function parse(InlineParserContext $inlineContext): bool { $cursor = $inlineContext->getCursor(); $origin = $cursor->getPosition() + 1; $offset = match (true) { - $this->parser instanceof CloseBracketParser => $this->getDelimiterOffset($inlineContext, ['[', '!']), + $this->parser instanceof CloseBracketParser => $this->getDelimiterOffset($inlineContext), default => $cursor->getPosition(), }; @@ -193,20 +193,16 @@ public function finalize(): void { $this->incomplete = new WeakMap(); } - /** - * @param list $characters - */ - private function getDelimiterOffset(InlineParserContext $context, array $characters): int { - $delimiter = $context->getDelimiterStack()->searchByCharacter($characters); - $length = 0; - - if ($delimiter instanceof DelimiterInterface && $delimiter->isActive()) { - // We do not use `$delimiter->getLength()` here because `$delimiter->getIndex()` - // seems incorrect for some delimiters e.g. for `![`. - $length = (int) $delimiter->getIndex() - mb_strlen($delimiter->getInlineNode()->getLiteral()); + private function getDelimiterOffset(InlineParserContext $context): int { + $offset = 0; + $bracket = $context->getDelimiterStack()->getLastBracket(); + $node = $bracket?->getNode(); + + if ($bracket !== null && $node instanceof StringContainerInterface) { + $offset = $bracket->getPosition() - mb_strlen($node->getLiteral()); } - return $length; + return $offset; } private function save( From ba72abb1ac91d104338f87f6ca4b91c908545b0b Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Tue, 10 Dec 2024 15:50:10 +0400 Subject: [PATCH 15/16] test(formatter): `\LastDragon_ru\LaraASP\Formatter\FormatterTest::testOrdinal()` fix. --- packages/formatter/src/FormatterTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/formatter/src/FormatterTest.php b/packages/formatter/src/FormatterTest.php index 206463b8..186182d2 100644 --- a/packages/formatter/src/FormatterTest.php +++ b/packages/formatter/src/FormatterTest.php @@ -21,6 +21,7 @@ use PHPUnit\Framework\Attributes\CoversClass; use function pow; +use function rtrim; use function str_replace; use const PHP_INT_MAX; @@ -113,7 +114,7 @@ public function testDecimalConfig(): void { public function testOrdinal(): void { self::assertEquals('1st', $this->formatter->ordinal(1)); - self::assertEquals('10.', $this->formatter->forLocale('ru_RU')->ordinal(10)); + self::assertEquals('10', rtrim($this->formatter->forLocale('ru_RU')->ordinal(10), '.')); } public function testString(): void { From 4db1265fe03b2d2ec0b68d25314275514626a2a1 Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:01:55 +0400 Subject: [PATCH 16/16] Composer classmap warnings fix. --- composer.json | 1 + packages/graphql/src/Builder/ContextTest.php | 3 +-- packages/migrator/composer.json | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 7ebf7354..ac9730c7 100644 --- a/composer.json +++ b/composer.json @@ -136,6 +136,7 @@ "packages/graphql-printer/docs/", "packages/graphql/docs/", "packages/migrator/docs/", + "packages/migrator/src/Migrations/MigratorTest/raw/", "packages/serializer/docs/", "packages/spa/docs/", "packages/testing/docs/" diff --git a/packages/graphql/src/Builder/ContextTest.php b/packages/graphql/src/Builder/ContextTest.php index e4222816..98116c01 100644 --- a/packages/graphql/src/Builder/ContextTest.php +++ b/packages/graphql/src/Builder/ContextTest.php @@ -1,8 +1,7 @@