From ac43fee0d8d1307cf7eac4554b438db4219ab990 Mon Sep 17 00:00:00 2001 From: stijnvanhoey Date: Mon, 13 Dec 2021 18:19:27 +0100 Subject: [PATCH] Add exercise numbers on conversion --- nbtutor/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nbtutor/__init__.py b/nbtutor/__init__.py index e276483..f1feb61 100644 --- a/nbtutor/__init__.py +++ b/nbtutor/__init__.py @@ -22,6 +22,7 @@ def __init__(self, **kw): os.makedirs(self.solutions_dir) self.solution_count = 1 + self.exercise_count = 1 super(Preprocessor, self).__init__(**kw) @@ -38,4 +39,9 @@ def preprocess_cell(self, cell, resources, index): self.solution_count += 1 + if cell.cell_type == "markdown" and "EXERCISE" in cell.source: + cell.source = cell.source.replace('EXERCISE', f'EXERCISE {self.exercise_count}') + self.exercise_count += 1 + return cell, resources +