{%import "executePythonDisplayMacro.js" as display with context%}
<script>
    //Marker {{prefix}}
    setTimeout(function(){
        var cells=IPython.notebook.get_cells().filter(function(cell){
            if(!cell.output_area || !cell.output_area.outputs){
                return false;
            }
            return cell.output_area.outputs.filter(function(output){
                if (output.output_type==="display_data"&&output.data&&output.data["text/html"]){
                    return output.data["text/html"].includes("//Marker {{prefix}}")
                }
                return false;
            }).length > 0;
        });
        if(cells.length>0){
            var cell=cells[0];
            var cellId=cell.cell_id;
            var cellMetadata=cell._metadata.pixiedust;
            var old_msg_id = cell.last_msg_id;
            if (old_msg_id) {
                cell.kernel.clear_callbacks_for_msg(old_msg_id);
            }
            function getCellWidth(){
                try{
                    return cell.input[0].clientWidth
                }catch(e){
                    console.log(e)
                }
            }
            var snifferOptions = [{'nostore_cw':getCellWidth()},{'nostore_pixiedust':(typeof pixiedust != "undefined")}];
            {%if org_params%}
                snifferOptions.push({'org_params':'{{org_params}}'});
            {%endif%}
            {%for cb in this.snifferCallbacks%}
                snifferOptions.push({{cb()}})
            {%endfor%}
            {% call display.executeDisplay() %}
                for (var o in snifferOptions){
                    addOptions(snifferOptions[o]);
                }
                addOptions({"showchrome":"true"});
            {% endcall %}
        }else{
            alert("An error occurred, unable to access cell id");
        }
    },500);
</script>