'Return a styled HTML snippet for the current buffer.
"include_styling" (optional, default False) is a boolean
indicating if the CSS/JS/informational-HTML should be
included.
"include_html" (optional, default False) is a boolean indicating
if the HTML output should be wrapped into a complete HTML
document.
"title" is the HTML document title to use if \'include_html\' is
True.
"do_trg" (optional, default False) indicates that trigger
handling should be done. This implies do_eval=True.
"do_eval" (optional, default False) indicates that completion
eval should be done.'

def to_html(self, include_styling=False, include_html=False, title=None, do_trg=False, do_eval=False):

    from cStringIO import StringIO
    html = StringIO()
    if include_html:
        html.write(('<!DOCTYPE    html    PUBLIC    "-//W3C//DTD    XHTML    1.0    Strict//EN"\n                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n<html    xmlns="http://www.w3.org/1999/xhtml"    lang="en"    xml:lang="en">\n<head>\n<meta    http-equiv="Content-Type"    content="text/html;    charset=utf-8"    />\n<title>%s</title>\n</head>\n<body>\n' % title))
    if include_styling:
        html.write('\n<script    type="application/x-javascript">\n                function    show_class(span)    {\n                                var    infobox    =    document.getElementById("infobox");\n                                infobox.innerHTML    =    span.getAttribute("class");\n                }\n</script>\n\n<style>\n#infobox    {\n                border:    4px    solid    #e0e0e0;\n                background-color:    #f0f0f0;\n                padding:    10px;\n                position:    fixed;\n                top:    5px;\n                right:    5px;\n}\n\n/*    CSS    Tooltips:    http://www.communitymx.com/content/article.cfm?cid=4E2C0    */\ndiv.code    span.trg    {\n                font:    small-caption;\n                vertical-align:    bottom;\n                color:    green;\n                position:    relative;\n                cursor:    crosshair;\n}\ndiv.code    span.trg-info    {\n                display:    none;\n                z-index:    25;\n                cursor:    text;\n                min-width:    25em;\n                white-space:    nowrap;\n}\ndiv.code    span.trg:hover    span.trg-info    {\n                z-index:    26;\n                position:    absolute;\n                top:    1.0em;\n                left:    0.0em;\n                display:    block;\n                padding:    4px;\n                background-color:    #f0f0f0;\n                border:    1px    solid    #e0e0e0;\n}\nspan.trg-evalerror        {    width:    50em;    color:    red    !important;    }\nspan.trg-error                        {    width:    50em;    color:    red    !important;    }\nspan.trg-notatrg                {    color:    blue    !important;    }\nspan.trg-noresults        {    color:    orange    !important;    }\ntd.trg-evallog    {\n                color:    grey;\n                border-left:    1px    solid    grey;\n                padding-left:    5px;\n}\n\n/*    token    highlighting    and    debugging    info    */\ndiv.code    span:hover    {\n                background-color:    #e0e0e0;\n}\n\ndiv.code    span.udl-region:hover    {\n                background-color:    #f0f0f0;\n}\n\n/*    language-neutral    syntax    coloring    */\ndiv.code    {\n                font-family:    "Courier    New",    Courier,    monospace;\n                font-size:    small;\n}\n\ndiv.code    .comments                {    color:    grey;    }\ndiv.code    .keywords                {    font-weight:    bold;    }\ndiv.code    .identifiers    {    color:    black;    }\ndiv.code    .strings                    {    color:    blue;    }\ndiv.code    .classes,\ndiv.code    .functions            {    color:    green;    }\ndiv.code    .stderr                        {    background-color:    red;    }\ndiv.code    .stdout                        {    background-color:    blue;    }\ndiv.code    .tags                                {    color:    red;    }\n\n</style>\n\n<div    id="infobox"></div>\n')
    html.write(('<div    class="code    %s">\n' % self.lang.lower()))
    curr_udl_region = None
    ch = last_ch = None
    for token in self.accessor.gen_tokens():
        css_classes = self.style_names_from_style_num(token['style'])
        if (css_classes and css_classes[0].startswith('SCE_UDL_')):
            udl_region = css_classes[0].split('_')[2]
            if (udl_region == curr_udl_region):
                pass
            else:
                if curr_udl_region:
                    html.write('\n</span>\n')
                html.write('\n<span    class="udl-region">\n')
                curr_udl_region = udl_region
        html.write(('<span    class="%s"    onmouseover="show_class(event.target);">' % '    '.join(css_classes)))
        for (i, ch) in enumerate(token['text']):
            if ((ch == '\n') and (last_ch == '\r')):
                continue
            if do_trg:
                try:
                    trg = self.trg_from_pos((token['start_index'] + i))
                except CodeIntelError as ex:
                    html.write(self._html_from_trg_error(ex))
                else:
                    if (trg is not None):
                        html.write(self._html_from_trg(trg, do_eval=do_eval))
            html.write(_htmlescape(ch, quote=True, whitespace=True))
            last_ch = ch
        html.write('</span>')
    if curr_udl_region:
        html.write('\n</span>\n')
    html.write('</div>\n')
    if include_html:
        html.write('\n</body>\n</html>\n')
    return html.getvalue()
