Skip to content

Exclude code blocks that aren't run #5307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 31, 2025
Merged

Conversation

LiamConnors
Copy link
Member

In the docs we have Python code which is formatted as Python code

image

but not run. In the Markdown it looks like this, it's inside blocks:

<!-- #region -->
Code that relied on the `add_*` methods to return a reference to the newly created trace will need to be updated to access the trace from the returned figure.  This can be done by appending `.data[-1]` to the add trace expression.

Here is an example of a version 3 code snippet that adds a scatter trace to a figure, assigns the result to a variable named `scatter`, and then modifies the marker size of the scatter trace.

```python
import plotly.graph_objs as go
fig = go.Figure()
scatter = fig.add_trace(go.Scatter(y=[2, 3, 1]))
scatter.marker.size = 20

In version 4, this would be replaced with the following:

import plotly.graph_objects as go
fig = go.Figure()
scatter = fig.add_trace(go.Scatter(y=[2, 3, 1])).data[-1]
scatter.marker.size = 20

This PR modifies the `run_markdown.py` script to not run these sections. 
Also updates the test script to use the same function as `run_markdown.py` uses

@LiamConnors LiamConnors requested a review from gvwilson July 30, 2025 19:00
@gvwilson gvwilson merged commit e45f54c into mkdocs-conversion Jul 31, 2025
4 of 7 checks passed
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.

2 participants