1<?php
2
3/*
4 * This file is part of the league/commonmark package.
5 *
6 * (c) Colin O'Dell <colinodell@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace League\CommonMark\Extension\TaskList;
13
14use League\CommonMark\ElementRendererInterface;
15use League\CommonMark\HtmlElement;
16use League\CommonMark\Inline\Element\AbstractInline;
17use League\CommonMark\Inline\Renderer\InlineRendererInterface;
18
19final class TaskListItemMarkerRenderer implements InlineRendererInterface
20{
21    /**
22     * @param TaskListItemMarker       $inline
23     * @param ElementRendererInterface $htmlRenderer
24     *
25     * @return HtmlElement|string|null
26     */
27    public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
28    {
29        if (!($inline instanceof TaskListItemMarker)) {
30            throw new \InvalidArgumentException('Incompatible inline type: ' . \get_class($inline));
31        }
32
33        $checkbox = new HtmlElement('input', [], '', true);
34
35        if ($inline->isChecked()) {
36            $checkbox->setAttribute('checked', '');
37        }
38
39        $checkbox->setAttribute('disabled', '');
40        $checkbox->setAttribute('type', 'checkbox');
41
42        return $checkbox;
43    }
44}
45