<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def codemirror_instance(config_name, varname, element_id, assets=True):
 """ Return HTML to init a CodeMirror instance for an element. This will output the whole HTML needed to initialize a CodeMirror instance with needed assets loading. Assets can be omitted with the ``assets`` option. Example: :: {% load djangocodemirror_tags %} {% codemirror_instance 'a-config-name' 'foo_codemirror' 'foo' %} Arguments: config_name (string):
 A registred config name. varname (string):
 A Javascript variable name. element_id (string):
 An HTML element identifier (without leading ``#``) to attach to a CodeMirror instance. Keyword Arguments: assets (Bool):
 Adds needed assets before the HTML if ``True``, else only CodeMirror instance will be outputed. Default value is ``True``. Returns: string: HTML. """

    output = io.StringIO()

    manifesto = CodemirrorAssetTagRender()
    manifesto.register(config_name)

    if assets:
        output.write(manifesto.css_html())
        output.write(manifesto.js_html())

    html = manifesto.codemirror_html(config_name, varname, element_id)
    output.write(html)

    content = output.getvalue()
    output.close()

    return mark_safe(content)