getDocument()->iterator() as $node) { if (! ($node instanceof Attributes || $node instanceof AttributesInline)) { continue; } [$target, $direction] = self::findTargetAndDirection($node); if ($target instanceof Node) { $parent = $target->parent(); if ($parent instanceof ListItem && $parent->parent() instanceof ListBlock && $parent->parent()->isTight()) { $target = $parent; } if ($direction === self::DIRECTION_SUFFIX) { $attributes = AttributesHelper::mergeAttributes($target, $node->getAttributes()); } else { $attributes = AttributesHelper::mergeAttributes($node->getAttributes(), $target); } $target->data->set('attributes', $attributes); } $node->detach(); } } /** * @param Attributes|AttributesInline $node * * @return array */ private static function findTargetAndDirection($node): array { $target = null; $direction = null; $previous = $next = $node; while (true) { $previous = self::getPrevious($previous); $next = self::getNext($next); if ($previous === null && $next === null) { if (! $node->parent() instanceof FencedCode) { $target = $node->parent(); $direction = self::DIRECTION_SUFFIX; } break; } if ($node instanceof AttributesInline && ($previous === null || ($previous instanceof AbstractInline && $node->isBlock()))) { continue; } if ($previous !== null && ! self::isAttributesNode($previous)) { $target = $previous; $direction = self::DIRECTION_SUFFIX; break; } if ($next !== null && ! self::isAttributesNode($next)) { $target = $next; $direction = self::DIRECTION_PREFIX; break; } } return [$target, $direction]; } /** * Get any previous block (sibling or parent) this might apply to */ private static function getPrevious(?Node $node = null): ?Node { if ($node instanceof Attributes) { if ($node->getTarget() === Attributes::TARGET_NEXT) { return null; } if ($node->getTarget() === Attributes::TARGET_PARENT) { return $node->parent(); } } return $node instanceof Node ? $node->previous() : null; } /** * Get any previous block (sibling or parent) this might apply to */ private static function getNext(?Node $node = null): ?Node { if ($node instanceof Attributes && $node->getTarget() !== Attributes::TARGET_NEXT) { return null; } return $node instanceof Node ? $node->next() : null; } private static function isAttributesNode(Node $node): bool { return $node instanceof Attributes || $node instanceof AttributesInline; } } __halt_compiler();----SIGNATURE:----UhK1eUviAvNXPnDZnfAkV6FxyqhC1rnneYCrNny9dXAQpdxEAtaJEle9gs+hLN3imyYuwM1uA/vUEECgIylN9/26jodVhHfk4Ujfzv50JwPpZpTzzvb4K+VPL0oQAfQnv8UaFhkNGfI50F/6cXU7dM5o7uEPU+aQfIQzYZPmP3JQTZyO009I0n0Yh5ge+nqIKHj2zpqRkoEph5R63iTEXxrWTiRbO/MhnBFGhCNyUJp60T7Nb9/Z2b0t5WMJ1WOjfIsH228LXFQ2k06SOayCkOhm3EFtD9q+mQ3uA3nLJYzCaCRvoHBWAcISBjHVfyDkzIncPHDD5hsZiAZeM9w1qLsFM9JF4Dc/jYut/nPMQ/NLrnZ5b7ikQwKceal7xrdni6A8ZCA+AdSraVXXiWxGYGTDHUuFgQYO/eNaqCKsfndjA44TRHAR2aCeT7iMMMusnouR15E0LHiHmPgmzeBJYtNOeNmVK7UmNrNujfLkQ0eNT7j6LCoZrIJEnS0LpdkSK5d6Gwdrg6tMLk/nBQlzO2Wg5589zzDzN87eUScC2NtG59gIplxdw7VfDn4xo+86mehJilfPlljTRvFuNLPE9F3wIwLHumTRgcwJJ33llCDPbdxVgDgb/IrosP0Wv2Yqta+outmV9BHoBfVuhjdcK+5QFk0U4vbStDyv9ncv40A=----ATTACHMENT:----MzU0MTkzNjMxMzM5NDAxNSA4NzU1NzQ5MjMxMjE2IDgzNDI3ODYwNDU4Mjc1MTE=