{#
INPUT:

        - ``cell`` -- Cell instance

        - ``wrap`` - an integer stating column position to wrap lines. Defaults to
          configuration if not given.

        - ``div_wrap`` - a boolean stating whether to wrap ``div``.

        - ``do_print`` - a boolean stating whether the HTML is for
        print or not.

        - ``publish`` - a boolean; whether this is a published cell
#}
{% if do_print %}
    {% set wrap_ = 68 %}
    {% set div_wrap_ = true %}
{% else %}
    {% set wrap_ = wrap %}
    {% set div_wrap_ = div_wrap %}
{% endif %}
{% set cell_cls = "cell_evaluated" if cell.evaluated() or do_print or publish else "cell_not_evaluated" %}

{% if div_wrap_ %}
<div id="cell_outer_{{ cell.id() }}" class="cell_visible">
    <div id="cell_{{ cell.id() }}" class="{{ cell_cls }}">
{% endif %}
        {% if 'hideall' not in cell.percent_directives() %}
        {# input #}
        {% if not do_print and not publish %}
            <div class="insert_new_cell" id="insert_new_cell_before{{ cell.id() }}">
              <div class="ui-icon ui-icon-circle-plus wksht-icon_button" 
                id="insert_new_compute_cell_before{{ cell.id() }}" 
                title="{{ gettext('Click to insert new compute cell.') }}"></div>
                {% if not cell.worksheet().docbrowser() %}
                  <div class="ui-icon ui-icon-comment wksht-icon_button" 
                  id="insert_new_text_cell_before{{ cell.id() }}"
                  title="{{ gettext('Click to insert new rich-text cell.') }}"></div>
                {% endif %}
              <div class="legacy_insert_new_cell" id="legacy_new_cell_before{{ cell.id() }}"></div>
            </div>
            <script type="text/javascript">
                $("#insert_new_compute_cell_before{{ cell.id() }}").bind("click",function (e) {
                    insert_new_cell_before({{ '%r'|format(cell.id()) }});
                });
                {% if not cell.worksheet().docbrowser() %}
                $("#insert_new_text_cell_before{{ cell.id() }}").bind("click",function (e) {
                   insert_new_text_cell_before({{ '%r'|format(cell.id()) }});
                });
                $("#legacy_new_cell_before{{ cell.id() }}").bind("click",function (e) {
                   if (e.shiftKey){
                      insert_new_text_cell_before({{ '%r'|format(cell.id()) }});
                   } else {
                      insert_new_cell_before({{ '%r'|format(cell.id()) }});
                   }
                });
                {% endif %}
            </script>
        {% endif %}
            {% if 'hide' in cell.percent_directives() %}
                {% set input_cls = 'cell_input_hide' %}
            {% else %}
                {% set input_cls = 'cell_input' %}
            {% endif %}
            {% if publish and conf['pub_interact'] %}
                {# We don't condition on interact cells here, for the sake of a uniform appearance. #}
                <textarea class="{{ input_cls }}" rows="{{ (1, cell.input_text().strip()|number_of_rows(80))|max }}"
                          cols="80"
                          readonly="yes"
                          id="cell_input_{{ cell.id() }}"
                          >{{ cell.input_text().rstrip() }}</textarea>
                {% if cell.is_interactive_cell() %}
                    <a href="javascript:evaluate_cell({{ '%r'|format(cell.id()) }}, 0);"
                       class="eval_button_active"
                       id="eval_button{{ cell.id() }}"
                       title="Click here to reset this interactive cell">
                        reset
                    </a>
                {% endif %}
            {% elif do_print or publish %}
                <div class="cell_input_print">{{ cell.input_text().rstrip() }}&nbsp;</div>
            {% else %}
                <textarea class="{{ input_cls }}" rows="{{ (1, cell.input_text().strip()|number_of_rows(80))|max }}"
                          cols="80" spellcheck="false"
                          id="cell_input_{{ cell.id() }}">{{ cell.input_text().rstrip() }}</textarea>
                <input type="button"
                   class="eval_button"
                   id="eval_button{{ cell.id() }}" 
                   title="{{ gettext('Click here or press shift-return to evaluate') }}"
                   value="{{ gettext('evaluate') }}" />
            {% endif %}
            {# end input #}

            <div id="introspect_div_{{ cell.id() }}" class="introspection"></div>
        {% endif %}

        {% if do_print and cell.cell_output_type() == 'hidden' %}
        <pre>
        </pre>
        {% else %}
        {% set output_cls = 'cell_div_output_running' if cell.computing() else 'cell_div_output_' + cell.cell_output_type() %}
        <div class="cell_output_div">
            <table class="cell_output_box">
                <tr>
                    <td class="cell_number" id="cell_number_{{ cell.id() }}"
                        {{ '' if do_print else 'onClick=cycle_cell_output_type(%r);'|format(cell.id()) }} >
                        {% for i in range(7) %}&nbsp;{% endfor %}
                    </td>
                    <td class="output_cell">
                        <div class="{{ output_cls }}" id="cell_div_output_{{ cell.id() }}">
                            <div class="cell_output_{{ "print_" if do_print else '' }}{{ cell.cell_output_type() }}"
                                id="cell_output_{{ cell.id() }}">
                                {% if cell.introspect() %}
                                    {{ cell.output_text(0, html=true) | safe }}
                                {% else %}
                                    {{ cell.output_text(wrap_, html=true) | safe }}
                                {% endif %}
                            </div>
                            {% if not do_print %}
                                <div class="cell_output_{{ 'print_' if do_print else '' }}nowrap_{{ cell.cell_output_type() }}"
                                     id="cell_output_nowrap_{{ cell.id() }}">
                                    {{ cell.output_text(0, html=true) | safe }}
                                </div>
                            {% endif %}
                                <div class="cell_output_html_{{ cell.cell_output_type() }}"
                                     id="cell_output_html_{{ cell.id() }}">
                                    {{ cell.output_html() | safe }}
                                </div>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
        {% endif %}

{% if div_wrap_ %}
    </div>
</div>
{% endif %}
