{% from "www/macros/livecode.html" import LiveCodeEditorJS, LiveCodeEditor with context %}

<div class="exercise">
  <h2>Exercise {{exercise.index_label}}: {{ exercise.title }}</h2>
  <div class="exercise-description">{{frappe.utils.md_to_html(exercise.description)}}</div>

  {% if exercise.image %}
  <div class="exercise-image">{{exercise.image}}</div>
  {% endif %}

  {% set submission = exercise.get_user_submission() %}

  {{ LiveCodeEditor(exercise.name,
        code=submission.solution if submission else exercise.code,
        reset_code=exercise.code,
        is_exercise=True,
        last_submitted=submission and submission.creation) }}
</div>
