Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
371838e
Fix excess whitespace in streaming output from code cells
mmcky Nov 20, 2025
b8c9bc4
Add test for streaming output spacing
mmcky Nov 20, 2025
9e744a2
fix: pre-commit
mmcky Nov 20, 2025
fa73064
Fix CSS placement: Move streaming output fix outside dark-theme block
mmcky Nov 21, 2025
923d57c
Add !important to override MyST-NB default margin
mmcky Nov 21, 2025
3fc1a45
Update test notebook with proper streaming output structure
mmcky Nov 21, 2025
9f52b9e
fix: pre-commit
mmcky Nov 21, 2025
4327e26
Fix: Remove margins from pre elements in streaming output
mmcky Nov 21, 2025
8c26ab8
fix: pre-commit
mmcky Nov 21, 2025
3213b8f
Fix: Use shorthand margin property to override _syntax.scss
mmcky Nov 21, 2025
89c7190
Fix: Add missing line break after closing brace
mmcky Nov 21, 2025
0eba0f5
fix: pre-commit
mmcky Nov 21, 2025
4fb6c81
Fix: Also remove padding from pre elements in streaming output
mmcky Nov 21, 2025
5d3c701
docs: Add pre-commit reminder to copilot instructions
mmcky Nov 21, 2025
55fc75e
Fix: Add line-height override for streaming output pre elements
mmcky Nov 21, 2025
0bb9534
Remove line-height override causing scrollbars in streaming output
mmcky Nov 21, 2025
67596fd
Apply streaming output spacing fix to all stream elements, not just c…
mmcky Nov 21, 2025
8cc3853
Tighten streaming output spacing with line-height control and full pa…
mmcky Nov 21, 2025
332d98b
Revert "Tighten streaming output spacing with line-height control and…
mmcky Nov 21, 2025
d33b51a
Achieve zero spacing between streaming output lines with line-height:…
mmcky Nov 21, 2025
a32ba28
Revert "Achieve zero spacing between streaming output lines with line…
mmcky Nov 21, 2025
ee075be
Replace CSS workarounds with Sphinx post-transform to merge consecuti…
mmcky Nov 21, 2025
0200066
Revert to simple CSS-only fix for streaming output spacing
mmcky Nov 21, 2025
4975c07
Add comprehensive CSS fix for streaming output spacing
mmcky Nov 21, 2025
4864339
Stick with CSS-only solution after transform experiments
mmcky Nov 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ src/quantecon_book_theme/
- **Regression tests**: Tests compare generated HTML against golden files in `tests/test_build/`

### Code Quality Workflow
- Always run `pre-commit run --all-files` before committing
- **CRITICAL**: ALWAYS run `pre-commit run --all-files` before committing to GitHub
- Pre-commit includes: black (formatting), flake8 (linting), YAML/JSON validation
- CI will fail if pre-commit checks don't pass
- If you make changes to Python or SCSS files, run pre-commit before `git commit`

## Troubleshooting

Expand Down Expand Up @@ -116,10 +117,13 @@ pre-commit install
# Development workflow
npm run build # Compile assets (2.5-3 seconds, VALIDATED)
tox -e docs-live # Live development server (5-10 minutes)
pre-commit run --all-files # Code quality checks (2-5 minutes, VALIDATED)
pre-commit run --all-files # Code quality checks (2-5 minutes, VALIDATED) - RUN BEFORE COMMITTING
flake8 src/ # Python linting (few seconds, VALIDATED)
black --check src/ # Formatting check (few seconds, VALIDATED)

# Before committing to GitHub
pre-commit run --all-files # CRITICAL: Always run before git commit

# Testing and CI
tox # Full test suite (5-15 minutes)
tox -e docs-update # Build documentation (5-15 minutes)
Expand Down
21 changes: 21 additions & 0 deletions src/quantecon_book_theme/assets/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,27 @@ body {
}
}

// Fix excess spacing in streaming output (Issue #325)
// Remove all spacing between consecutive streaming outputs
.cell_output .output.stream + .output.stream {
margin-top: 0 !important;
}

// Remove internal spacing from all streaming output elements
.cell_output .output.stream {
.highlight {
margin-top: 0 !important;
margin-bottom: 0 !important;

// Remove margin and padding from pre elements
pre {
margin: 0 !important;
padding-top: 0 !important;
padding-bottom: 0 !important;
}
}
}

.section,
.reference,
.math {
Expand Down
1 change: 1 addition & 0 deletions tests/sites/base/section1/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
```{toctree}
page1
ntbk
ntbk_streaming
ntbkmd
ntbk_octave
ntbk_julia
Expand Down
117 changes: 117 additions & 0 deletions tests/sites/base/section1/ntbk_streaming.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Test Streaming Output\n",
"\n",
"This notebook tests streaming output from multiple print statements."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Error at iteration 25 is 40.0.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Error at iteration 50 is 20.0.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Error at iteration 75 is 13.333333333333334.\n"
]
}
],
"source": [
"# Test with streaming output from loop\n",
"# Each print statement creates a separate stream output\n",
"for i in [25, 50, 75]:\n",
" error = 100 / (i / 10)\n",
" print(f\"Error at iteration {i} is {error}.\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Line 1\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Line 2\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Line 3\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Line 4\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Line 5\n"
]
}
],
"source": [
"# Test with multiple consecutive print statements\n",
"# Each creates a separate stream output\n",
"for i in range(1, 6):\n",
" print(f\"Line {i}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.0"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
46 changes: 46 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,49 @@ def test_qetheme_code_style(sphinx_build):
# String "true" should be treated as True
assert "use-pygments-style" not in body_tag.get("class", [])
sphinx_build.clean()


def test_streaming_output_spacing(sphinx_build):
"""Test that streaming output structure supports CSS spacing fix.

This test verifies the fix for issue #325 where consecutive stream outputs
have comprehensive CSS applied to remove excessive spacing.
"""
sphinx_build.copy()
sphinx_build.build()

# Get the streaming output notebook page
streaming_html = sphinx_build.get("section1/ntbk_streaming.html")

# Find all stream output divs
stream_outputs = streaming_html.find_all("div", class_="output")
stream_divs = [div for div in stream_outputs if "stream" in div.get("class", [])]

# Should have multiple stream outputs from the test notebook
assert (
len(stream_divs) >= 8
), f"Should have at least 8 streaming output elements, found {len(stream_divs)}"

# Verify we have consecutive streaming outputs (adjacent siblings)
cell_outputs = streaming_html.find_all("div", class_="cell_output")
assert len(cell_outputs) >= 2, "Should have at least 2 cells with outputs"

# At least one cell should have consecutive stream outputs for CSS to target
found_consecutive = False
for cell_output in cell_outputs:
stream_children = [
child
for child in cell_output.children
if child.name == "div"
and "output" in child.get("class", [])
and "stream" in child.get("class", [])
]
if len(stream_children) >= 2:
found_consecutive = True
break

assert (
found_consecutive
), "Should have consecutive stream outputs for CSS fix to apply"

sphinx_build.clean()
11 changes: 8 additions & 3 deletions tests/test_build/test_build_book.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,24 @@
3.2. A test notebook
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="section1/ntbk_streaming.html">
3.3. Test Streaming Output
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="section1/ntbkmd.html">
3.3. Section 1 page1
3.4. Section 1 page1
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="section1/ntbk_octave.html">
3.4. Octave
3.5. Octave
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="section1/ntbk_julia.html">
3.5. Julia
3.6. Julia
</a>
</li>
</ul>
Expand Down
Loading