Get html for an Altair chart

def _get_altair_html_(self, chart_obj, slug):
        """
        Get html for an Altair chart
        """
        try:
            json_data = chart_obj.to_json(indent=0)
        except Exception as e:
            self.err(e)
        html = '<div id="' + slug + '"></div>\n'
        html += '<script type="text/javascript">'
        html += 'var spec = ' + json_data.replace("\n", "") + ";"
        html += """
        var embed_opt = {"mode": "vega-lite"};
        function showError(altel, error){
            altel.innerHTML = ('<div class="error">'
                            + '<p>JavaScript Error: ' + error.message + '</p>'
                            + "<p>This usually means there's a typo in your chart specification. "
                            + "See the javascript console for the full traceback.</p>"
                            + '</div>');
            throw error;
        };\n"""
        html += "const el_" + slug + " = document.getElementById('" + slug + "');"
        html += "vegaEmbed('#" + slug + "', spec, embed_opt)"
        html += ".catch(error => showError(el_" + slug + ", error));"
        html += '</script>'
        return html