#NEWLINE# def code_block( message , lang = None , name = None , lines = None , isBad = False ) : #NEWLINE# #INDENT# 'Return a string code block.\n\n    Note that the code block should start on a new line and will insert\n    a blank line at the start and end of itself.  If there is already a\n    preceeding blank line then the block will not display correctly.\n\n    e.g. good:\n        "hello\\n" + code_block("goodbye")\n\n    e.g. bad:\n        "hello" + code_block("goodbye")\n\n    e.g. bad:\n        "hello\\n\\n" + code_block("goodbye")\n\n    >>> code_block("hello")\n    \'\\n```hello```\\n\\n\'\n\n    :message: the string to be formatted as a code block\n    :lang: language that the code block is in, e.g. \'text\', \'html\'\n    :name: name of the file the block represents\n    :lines: number of lines to limit the viewport to (will have scrollbars)\n    :isBad: whether to format the snippet as a \'counter example\'\n    :returns: string of the new wrapped code block\n\n    ' #NEWLINE# block = '\n```' #NEWLINE# attributes = [ ] #NEWLINE# if ( lang is not None ) : #NEWLINE# #INDENT# attributes . append ( ( 'lang=' + name ) ) #NEWLINE# #UNINDENT# if ( name is not None ) : #NEWLINE# #INDENT# attributes . append ( ( 'name=' + name ) ) #NEWLINE# #UNINDENT# if ( lines is not None ) : #NEWLINE# #INDENT# attributes . append ( ( 'lines=' + str ( int ( lines ) ) ) ) #NEWLINE# #UNINDENT# if isBad : #NEWLINE# #INDENT# attributes . append ( 'counterexample' ) #NEWLINE# #UNINDENT# if attributes : #NEWLINE# #INDENT# block += ( ', ' . join ( attributes ) + '\n' ) #NEWLINE# #UNINDENT# block += ( message + '```\n\n' ) #NEWLINE# return block