Skip to content

Commit 37f1114

Browse files
committed
fix: newline issues with tests
1 parent 5cf3ba9 commit 37f1114

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

mkquartodocs/extension.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ def _trim_line(
9090
def get_lines_content(self, start: Cursor, end: Cursor) -> list[str]:
9191
# TODO ... this is an off-by 1 error nightmare ...
9292
# Some unit testing might be really worth it ...
93+
if start == end:
94+
return []
95+
9396
if start.line == end.line:
9497
return [self._trim_line(self.lines[start.line], start=start, end=end)]
9598

@@ -311,7 +314,6 @@ def _into_output_lines_cell(self, file_content: FileContent) -> list[str]:
311314
if isinstance(self.end, UnknownEnd):
312315
raise ValueError(f"BlockContext {self} has no end")
313316
out = []
314-
out.append("\n\n")
315317
last_end = self.start.advance_line(1)
316318
tmp = self.find_inner_block(file_content, context=[], start=last_end)
317319
while tmp is not None:
@@ -323,7 +325,6 @@ def _into_output_lines_cell(self, file_content: FileContent) -> list[str]:
323325
tmp = self.find_inner_block(file_content, context=[], start=last_end)
324326

325327
out.extend(file_content.get_lines_content(last_end, self.end.advance_line(-1)))
326-
out.append("\n\n")
327328

328329
return out
329330

@@ -341,7 +342,7 @@ def _into_output_lines_cell_elem(self, file_content: FileContent) -> list[str]:
341342
)
342343

343344
out.append(admon_candidates[0])
344-
out.append("\n")
345+
out.append("")
345346

346347
internal = []
347348
last_end = self.start.advance_line(1)
@@ -376,7 +377,7 @@ def _into_output_lines_cell_elem(self, file_content: FileContent) -> list[str]:
376377
file_content.get_lines_content(last_end, self.end.advance_line(0))
377378
)
378379
out.extend([" " * 4 + line for line in internal])
379-
out.append("\n\n")
380+
out.append("")
380381

381382
return out
382383

@@ -387,7 +388,6 @@ def _into_output_lines_codeblock(
387388
if isinstance(self.end, UnknownEnd):
388389
raise ValueError(f"BlockContext {self} has no end")
389390
out = []
390-
out.append("\n\n")
391391
language = ""
392392
if self.attributes:
393393
language = self.attributes[0]
@@ -403,7 +403,6 @@ def _into_output_lines_codeblock(
403403

404404
out.extend(file_content.get_lines_content(last_end, self.end.advance_line(0)))
405405
out.append(f"{self.delimiter}")
406-
out.append("\n\n")
407406
return out
408407

409408

tests/test_preprocessor.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,18 @@
3232
"""
3333

3434
EXAMPLE_OUTPUT_FILE = """
35-
``` {.python .cell-code}
35+
```python
3636
import warnings
3737
warnings.warn("This is a warning")
38+
3839
```
3940
40-
!!! warning "stderr"
41-
... UserWarning: This is a warning
42-
warnings.warn("This is a warning")
41+
42+
43+
???+ warning "stderr"
44+
45+
... UserWarning: This is a warning
46+
warnings.warn("This is a warning")
4347
"""
4448

4549

@@ -49,24 +53,14 @@ def test_conversion():
4953
# Right now I write a lot of ... unnecessary
5054
# newlines to be safe but I could trim it ...
5155
assert out == [
52-
"\n\n",
53-
"",
5456
'???+ note "output"',
55-
"\n",
56-
" ",
57-
"\n\n",
5857
"",
59-
"\n\n",
6058
"",
61-
"\n\n",
6259
"",
63-
"\n\n",
64-
"```python",
6560
"",
61+
"```python",
6662
"```",
67-
"\n\n",
6863
"",
69-
"\n\n",
7064
"",
7165
]
7266

0 commit comments

Comments
 (0)