def code_block(code: str = None, path: str = None, language_id: str = None, title: str = None, caption: str = None): """ Adds a block of syntax highlighted code to the display from either the supplied code argument, or from the code file specified by the path argument. :param code: A string containing the code to be added to the display :param path: A path to a file containing code to be added to the display :param language_id: The language identifier that indicates what language should be used by the syntax highlighter. Valid values are any of the languages supported by the Pygments highlighter. :param title: If specified, the code block will include a title bar with the value of this argument :param caption: If specified, the code block will include a caption box below the code that contains the value of this argument """ environ.abort_thread() r = _get_report() r.append_body( render.code_block(block=code, path=path, language=language_id, title=title, caption=caption)) r.stdout_interceptor.write_source('{}\n'.format(code))
def test_code_block_from_file(self): """Should render a block of code from the specified path""" result = render.code_block(path=__file__, title='Render Test', caption=__file__) self.assertGreaterEqual(len(result), 1) self.assertTrue(result.find('Render Test') != -1)
def test_code_block_from_file(self): """Should render a block of code from the specified path""" result = render.code_block( path=__file__, title='Render Test', caption=__file__ ) self.assertGreaterEqual(len(result), 1) self.assertTrue(result.find('Render Test') != -1)
def test_code_block_from_string(self): """Should render block of code from string argument""" block = '\n'.join([ 'function add(a, b) {', ' return a + b;', '}', 'var test = add(2, 3);', 'console.log(test);' ]) result = render.code_block(block=block, title='Render Test JavaScript', caption='This is a caption', language='js') self.assertGreaterEqual(len(result), 1) self.assertTrue(result.find('caption') != -1)
def test_code_block_from_string(self): """Should render block of code from string argument""" block = '\n'.join([ 'function add(a, b) {', ' return a + b;', '}', 'var test = add(2, 3);', 'console.log(test);' ]) result = render.code_block( block=block, title='Render Test JavaScript', caption='This is a caption', language='js' ) self.assertGreaterEqual(len(result), 1) self.assertTrue(result.find('caption') != -1)
def code_block( code: str = None, path: str = None, language_id: str = None, title: str = None, caption: str = None ): """ Adds a block of syntax highlighted code to the display from either the supplied code argument, or from the code file specified by the path argument. :param code: A string containing the code to be added to the display :param path: A path to a file containing code to be added to the display :param language_id: The language identifier that indicates what language should be used by the syntax highlighter. Valid values are any of the languages supported by the Pygments highlighter. :param title: If specified, the code block will include a title bar with the value of this argument :param caption: If specified, the code block will include a caption box below the code that contains the value of this argument """ environ.abort_thread() r = _get_report() r.append_body(render.code_block( block=code, path=path, language=language_id, title=title, caption=caption )) r.stdout_interceptor.write_source('{}\n'.format(code))