def code_block(message, lang=None, name=None, lines=None, isBad=False):
    """Return a string code block.

    Note that the code block should start on a new line and will insert
    a blank line at the start and end of itself.  If there is already a
    preceeding blank line then the block will not display correctly.

    e.g. good:
        "hello\\n" + code_block("goodbye")

    e.g. bad:
        "hello" + code_block("goodbye")

    e.g. bad:
        "hello\\n\\n" + code_block("goodbye")

    >>> code_block("hello")
    '\\n```hello```\\n\\n'

    :message: the string to be formatted as a code block
    :lang: language that the code block is in, e.g. 'text', 'html'
    :name: name of the file the block represents
    :lines: number of lines to limit the viewport to (will have scrollbars)
    :isBad: whether to format the snippet as a 'counter example'
    :returns: string of the new wrapped code block

    """
    block = "\n```"

    attributes = []
    if lang is not None:
        attributes.append("lang=" + lang)
    if name is not None:
        attributes.append("name=" + name)
    if lines is not None:
        attributes.append("lines=" + str(int(lines)))
    if isBad:
        attributes.append("counterexample")

    if attributes:
        block += ', '.join(attributes) + "\n"

    block += message + "```\n\n"

    return block