Duplicated newlines in ansi-escaped-output

Open
#13,966 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
62/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
html, jupyter, python
Domain
frontend, web-dev

Research direction

Start with the self-contained Quarto example in the linked quarto-ansi repository and render it with the Jupyter engine to reproduce the duplicated newlines in the HTML ansi-escaped-output block. Trace the rendering path for that output and add regression coverage using the example; done means newline_para and carriage_para render with single line breaks.

Written by the indexing model from the issue text.

Description

bug
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

Dominant language
JavaScript
Stars
6k
Forks
458
Avg merge
1d 9h
Merged PRs (30d)
41

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from quarto-dev/quarto-cli

All issues in quarto-dev/quarto-cli

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.