private static function buildTag(string $name, ?string $content = null, array $attributes = [], bool $contentIsEncoded = false)
    {
        $result = '<' . htmlspecialchars($name);
        foreach ($attributes as $attributeName => $attributeValue) {
            if ($attributeValue === null || $attributeValue === false) {
                continue;
            }

            $result .= ' ' . htmlspecialchars(strval($attributeName));
            if ($attributeValue === true) {
                continue;
            }

            $result .= '="' . htmlspecialchars(strval($attributeValue)) . '"';
        }

        $result .= '>';

        if ($content !== null) {
            $result .= $contentIsEncoded ? $content : htmlspecialchars($content);
            $result .= '</' . htmlspecialchars($name) . '>';
        }

        return $result;
    }