<?php
declare(strict_types=1);
namespace League\CommonMark\Xml;
use League\CommonMark\Environment\EnvironmentInterface;
use League\CommonMark\Event\DocumentPreRenderEvent;
use League\CommonMark\Exception\InvalidArgumentException;
use League\CommonMark\Node\Block\Document;
use League\CommonMark\Node\Node;
use League\CommonMark\Node\StringContainerInterface;
use League\CommonMark\Output\RenderedContent;
use League\CommonMark\Output\RenderedContentInterface;
use League\CommonMark\Renderer\DocumentRendererInterface;
use League\CommonMark\Util\Xml;
final class XmlRenderer implements DocumentRendererInterface
{
private const INDENTATION = ' ';
private EnvironmentInterface $environment;
private XmlNodeRendererInterface $fallbackRenderer;
private array $rendererCache = [];
public function __construct(EnvironmentInterface $environment)
{
$this->environment = $environment;
$this->fallbackRenderer = new FallbackNodeXmlRenderer();
}
public function renderDocument(Document $document): RenderedContentInterface
{
$this->environment->dispatch(new DocumentPreRenderEvent($document, 'xml'));
$xml = '<?xml version="1.0" encoding="UTF-8"?>';
$indent = 0;
$walker = $document->walker();
while ($event = $walker->next()) {
$node = $event->getNode();