Skip to content

Commit

Permalink
Added Document::toInlinable()/Document::toSplittable().
Browse files Browse the repository at this point in the history
  • Loading branch information
LastDragon-ru committed Aug 13, 2024
1 parent 2c32f72 commit dcf573d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/documentator/src/Markdown/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Coordinate;
use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Location;
use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Locator;
use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\FootnotesPrefix;
use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\FootnotesRemove;
use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\ReferencesInline;
use LastDragon_ru\LaraASP\Documentator\Markdown\Mutations\ReferencesPrefix;
use LastDragon_ru\LaraASP\Documentator\Utils\Text;
use League\CommonMark\Extension\CommonMark\Node\Block\Heading;
use League\CommonMark\Extension\CommonMark\Node\Block\HtmlBlock;
Expand Down Expand Up @@ -130,6 +134,27 @@ public function mutate(Mutation ...$mutations): static {
return $document;
}

/**
* Renames all references/footnotes/etc to make possible inline the
* document into another document without conflicts/ambiguities.
*
* @return new<static>
*/
public function toInlinable(?string $seed = null): static {
return $this->mutate(new FootnotesPrefix($seed), new ReferencesPrefix($seed));
}

/**
* Inlines all references, removes footnotes, etc, to make possible
* extract any block/paragraph from the document without losing
* information.
*
* @return new<static>
*/
public function toSplittable(): static {
return $this->mutate(new FootnotesRemove(), new ReferencesInline());
}

protected function setContent(string $content): static {
$this->node = $this->parse($content);
$this->title = null;
Expand Down

0 comments on commit dcf573d

Please sign in to comment.