Skip to content

Duplicated newlines in ansi-escaped-output #13966

@JoFrhwld

Description

@JoFrhwld

I have:

  • searched the issue tracker for similar issues
  • installed the latest version of Quarto CLI
  • formatted my issue following the Bug Reports guide

Bug description

I'm reformatting strings with ansi codes to illustrate RegEx matches using the jupyter engine. When printing these strings, newlines are, for some reason, doubled in html output. If I replace the newlines with carriage returns, the carriage returns aren't doubled.

This is with quarto v1.8.27

The most relevant pre-existing issues I found here were #12132 and #12966, but neither mentioned issues with newlines

Steps to reproduce

Here's a qmd that will reproduce the issue. I've also got a github repo including the self-contained rendered html. https://github.com/JoFrhwld/quarto-ansi

````qmd
---
title: "Quarto Ansi"
format: 
  html:
    self-contained: true
engine: jupyter
---

```{python}
import re
```

```{python}
paragraph = """This is a paragraph.
This paragraph has multiple lines.
This paragraph has just one new line between each line."""
```

```{python}
print(paragraph)
```

```{python}
newline_para =  re.sub(
     r"( para)", 
     r'\033[31;1;4m' + r'\1' + r'\033[0m',
     paragraph
    )

carriage_para = re.sub(
  r"\n",
  r"\r",
  newline_para
)
```

```{python}
print(newline_para)
```

```{python}
print(carriage_para)
```
````

Actual behavior

From the rendered html, the result of printing newline_para is

<div class="cell-output cell-output-stdout">
<div class="ansi-escaped-output">
<pre>This is a<span style="font-weight:bold;text-decoration:underline" class="ansi-red-fg"> para</span>graph.

This<span style="font-weight:bold;text-decoration:underline" class="ansi-red-fg"> para</span>graph has multiple lines.

This<span style="font-weight:bold;text-decoration:underline" class="ansi-red-fg"> para</span>graph has just one new line between each line.
</pre>
</div>
</div>

While the result of printing carriage_para is

<div class="cell-output cell-output-stdout">
<div class="ansi-escaped-output">
<pre>This is a<span style="font-weight:bold;text-decoration:underline" class="ansi-red-fg"> para</span>graph.
This<span style="font-weight:bold;text-decoration:underline" class="ansi-red-fg"> para</span>graph has multiple lines.
This<span style="font-weight:bold;text-decoration:underline" class="ansi-red-fg"> para</span>graph has just one new line between each line.
</pre>
</div>
</div>

Expected behavior

I expected the rendered output for both would be

<div class="cell-output cell-output-stdout">
<div class="ansi-escaped-output">
<pre>This is a<span style="font-weight:bold;text-decoration:underline" class="ansi-red-fg"> para</span>graph.
This<span style="font-weight:bold;text-decoration:underline" class="ansi-red-fg"> para</span>graph has multiple lines.
This<span style="font-weight:bold;text-decoration:underline" class="ansi-red-fg"> para</span>graph has just one new line between each line.
</pre>
</div>
</div>

Your environment

  • IDE: Visual Studio Code v1.108.2, Positron v2026.01.0
  • Python: 3.13
  • OS: macOS Tahoe 26.2

Quarto check output

[✓] Checking environment information...
Quarto cache location: /Users/joseffruehwald/Library/Caches/quarto
[✓] Checking versions of quarto binary dependencies...
Pandoc version 3.6.3: OK
Dart Sass version 1.87.0: OK
Deno version 2.3.1: OK
Typst version 0.13.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
Version: 1.8.27
Path: /Applications/quarto/bin

[✓] Checking tools....................OK
TinyTeX: (external install)
Chromium: (not installed)

[✓] Checking LaTeX....................OK
Using: TinyTex
Path: /Users/joseffruehwald/Library/TinyTeX/bin/universal-darwin
Version: 2025

[✓] Checking Chrome Headless....................OK
Using: Chrome found on system
Path: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
Source: MacOS known location

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
Version: 3.13.5
Path: /Users/joseffruehwald/Documents/misc/quarto-ansi/.venv/bin/python3
Jupyter: 5.9.1
Kernels: python3, ir

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........OK
Version: 4.5.0
Path: /Library/Frameworks/R.framework/Resources
LibPaths:
- /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/library
knitr: 1.51
rmarkdown: 2.30

[✓] Checking Knitr engine render......OK

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions