-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract text node collapsing into a separate class for easier testing
- Loading branch information
1 parent
d48ea46
commit a7149ee
Showing
2 changed files
with
44 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the league/commonmark package. | ||
* | ||
* (c) Colin O'Dell <colinodell@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace League\CommonMark\Inline; | ||
|
||
use League\CommonMark\Inline\Element\Text; | ||
use League\CommonMark\Node\Node; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class AdjoiningTextCollapser | ||
{ | ||
/** | ||
* @param Node $container | ||
* | ||
* @internal | ||
*/ | ||
public static function collapseTextNodes(Node $container) | ||
{ | ||
$walker = $container->walker(); | ||
while (($event = $walker->next()) !== null) { | ||
if ($event->isEntering()) { | ||
$node = $event->getNode(); | ||
if ($node instanceof Text) { | ||
while (($next = $node->next()) && $next instanceof Text) { | ||
$node->append($next->getContent()); | ||
$next->detach(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters