diff --git a/src/DefinitionListItemDefinitionRenderer.php b/src/DefinitionListItemDefinitionRenderer.php index e133ec2..2b4abe1 100644 --- a/src/DefinitionListItemDefinitionRenderer.php +++ b/src/DefinitionListItemDefinitionRenderer.php @@ -14,6 +14,8 @@ public function render(AbstractBlock $block, ElementRendererInterface $htmlRende throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block)); } - return new HtmlElement('dd', [], $htmlRenderer->renderBlocks($block->children(), $inTightList)); + $attrs = $block->getData('attributes', []); + + return new HtmlElement('dd', $attrs, $htmlRenderer->renderBlocks($block->children(), $inTightList)); } } diff --git a/src/DefinitionListItemTermRenderer.php b/src/DefinitionListItemTermRenderer.php index 7fc0d7f..1fe2d78 100644 --- a/src/DefinitionListItemTermRenderer.php +++ b/src/DefinitionListItemTermRenderer.php @@ -14,6 +14,8 @@ public function render(AbstractBlock $block, ElementRendererInterface $htmlRende throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block)); } - return new HtmlElement('dt', [], $htmlRenderer->renderInlines($block->children())); + $attrs = $block->getData('attributes', []); + + return new HtmlElement('dt', $attrs, $htmlRenderer->renderInlines($block->children())); } } diff --git a/src/DefinitionListRenderer.php b/src/DefinitionListRenderer.php index be3287d..ebb7fb6 100644 --- a/src/DefinitionListRenderer.php +++ b/src/DefinitionListRenderer.php @@ -14,6 +14,8 @@ public function render(AbstractBlock $block, ElementRendererInterface $htmlRende throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block)); } - return new HtmlElement('dl', [], $htmlRenderer->renderBlocks($block->children(), $block->isTight())); + $attrs = $block->getData('attributes', []); + + return new HtmlElement('dl', $attrs, $htmlRenderer->renderBlocks($block->children(), $block->isTight())); } } diff --git a/test/AttributeRenderingTest.php b/test/AttributeRenderingTest.php new file mode 100644 index 0000000..e0c4fbe --- /dev/null +++ b/test/AttributeRenderingTest.php @@ -0,0 +1,49 @@ +addExtension(new DefinitionListExtension()); + $this->renderer = new HtmlRenderer($environment); + } + + public function testCorrectlyRendersAttributesOfDefinitionList(): void + { + $block = new DefinitionList(); + $block->data['attributes'] = ['id' => 'foo']; + $actualOutput = $this->renderer->renderBlock($block); + + $this->assertXmlStringEqualsXmlString("
", "$actualOutput"); + } + + public function testCorrectlyRendersAttributesOfDefinitionListItemDefinition(): void + { + $block = new DefinitionListItemDefinition(); + $block->data['attributes'] = ['id' => 'foo']; + $actualOutput = $this->renderer->renderBlock($block); + + $this->assertXmlStringEqualsXmlString("
", "$actualOutput"); + } + + public function testCorrectlyRendersAttributesOfDefinitionListItemTerm(): void + { + $block = new DefinitionListItemTerm([]); + $block->data['attributes'] = ['id' => 'foo']; + $actualOutput = $this->renderer->renderBlock($block); + + $this->assertXmlStringEqualsXmlString("
", "$actualOutput"); + } +}