Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 10, 2025

Fixed an issue where line breaks and indentation were not preserved correctly when using multi-line comments (triple quotes) in Markdown cells in the Interactive Window.

Problem

When writing Markdown cells using Python multi-line strings, the rendered output was losing line breaks and creating excessive spacing:

#%% [markdown]

"""
# H1 Title

description 1

- item 1
    - item 2
- item 3

description 2

- item 4
    - item 5
- item 6
"""

This would render with double line breaks between all elements, breaking the formatting of lists and code blocks.

Root Cause

The generateMarkdownFromCodeLines function was using appendLineFeed which adds line feeds to each array element. When cellFactory.ts then joined the result with '\n', it created double line breaks for empty lines:

  • appendLineFeed(['# H1 Title', '', 'description 1'])['# H1 Title\n', '\n', 'description 1']
  • Joining with '\n''# H1 Title\n\n\n\ndescription 1' (extra line breaks)

Solution

Removed the appendLineFeed call from generateMarkdownFromCodeLines. The function now returns a clean array of strings that preserves the original line structure when joined with '\n'.

Testing

  • Added comprehensive unit tests for the fix
  • Updated existing tests to expect correct behavior (no extra line breaks)
  • Verified both usage patterns work correctly:
    • cellFactory.ts uses .join('\n') for proper markdown rendering
    • interactiveWindow.ts uses .join('') for concatenation without separators

Fixes #9620.

@Copilot Copilot AI changed the title [WIP] Line breaks for multi-line comments in Markdown cells are broken (interactive Python) Fix line breaks for multi-line comments in Markdown cells (Interactive Window) Jun 10, 2025
@Copilot Copilot AI requested a review from amunger June 10, 2025 19:54
Copilot finished work on behalf of amunger June 10, 2025 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Line breaks for multi-line comments in Markdown cells are broken (interactive Python)
2 participants