|
28 | 28 | SEPARATOR = {True: MARKDOWN_SEPARATOR, False: CODE_SEPARATOR} |
29 | 29 |
|
30 | 30 |
|
31 | | -def _restore_quarto_cell_options(og_lines: list[str], lines: list[str]) -> list[str]: |
32 | | - """ |
33 | | - Restore the cell option comments #| at the start of the cell. |
34 | | -
|
35 | | - This comment like is typically changed to '# |' by third party tools. |
36 | | -
|
37 | | - This is for the cell options in quarto format as described at |
38 | | - https://quarto.org/docs/reference/cells/cells-jupyter.html. |
39 | | -
|
40 | | - Parameters |
41 | | - ---------- |
42 | | - og_lines |
43 | | - Original input lines. |
44 | | - lines |
45 | | - Lines after all formatting and magics restored. |
46 | | -
|
47 | | - Returns |
48 | | - ------- |
49 | | - list[str] |
50 | | - Lines with leading '# |' restored to '#|'. |
51 | | - """ |
52 | | - restored_lines = [] |
53 | | - i = 0 |
54 | | - # iteration logic should be safe since all cell options are at the start |
55 | | - # and single lines so shouldn't suffer multi-line formatting before |
56 | | - # breaking out |
57 | | - for i, line in enumerate(lines): |
58 | | - if not line.startswith("# |") or not og_lines[i].startswith("#|"): |
59 | | - # only leading '#|' are cell options |
60 | | - # if we encounter a line without, then all following are not |
61 | | - # we also skip if the formatting tool hasn't changed '#|' to '# |' |
62 | | - # since that means the formatter is handling qmd lines properly |
63 | | - restored_lines.append(line) |
64 | | - break |
65 | | - restored_lines.append("#|" + line[3:]) |
66 | | - restored_lines.extend(lines[i + 1 :]) |
67 | | - return restored_lines |
68 | | - |
69 | | - |
70 | 31 | def _restore_semicolon( |
71 | 32 | source: str, |
72 | 33 | cell_number: int, |
@@ -317,8 +278,6 @@ def mutate( # pylint: disable=too-many-locals,too-many-arguments |
317 | 278 | ) |
318 | 279 | if not new_source: |
319 | 280 | cells_to_remove.append(cell_number) |
320 | | - if notebook.endswith(".qmd"): |
321 | | - new_source = _restore_quarto_cell_options(cell["source"], new_source) |
322 | 281 | cell["source"] = new_source |
323 | 282 |
|
324 | 283 | if original_notebook_json == notebook_json: |
@@ -418,8 +377,6 @@ def diff( # pylint: disable=too-many-arguments |
418 | 377 | newlinesbefore[python_file], |
419 | 378 | newlinesafter[python_file], |
420 | 379 | ) |
421 | | - if notebook.endswith(".qmd"): |
422 | | - new_source = _restore_quarto_cell_options(cell["source"], new_source) |
423 | 380 | cell["source"][-1] += "\n" |
424 | 381 | if new_source: |
425 | 382 | new_source[-1] += "\n" |
|
0 commit comments