Skip to content

Commit 5b3e4ae

Browse files
committed
Remove orphaned content from examples.md template
The previous commit accidentally included generated content that was outside the proper OUTPUT sections. This commit removes the orphaned markdown examples and keeps only the template structure with PLACEHOLDER text that gets replaced during CI builds.
1 parent a362d1e commit 5b3e4ae

File tree

1 file changed

+4
-209
lines changed

1 file changed

+4
-209
lines changed

docs/examples.md

Lines changed: 4 additions & 209 deletions
Original file line numberDiff line numberDiff line change
@@ -12,72 +12,6 @@ Real-world examples demonstrating the power and flexibility of `markdown-code-ru
1212
<!-- CODE:END -->
1313
<!-- OUTPUT:START -->
1414
<!-- PLACEHOLDER --> Output is generated during CI build. We don't commit generated content to keep docs copyable and avoid recursion. See docs/docs_gen.py
15-
<!-- OUTPUT:END -->
16-
```
17-
18-
After running `markdown-code-runner`:
19-
```markdown
20-
This is an example of a simple code block:
21-
22-
<!-- CODE:START -->
23-
<!-- print('Hello, world!') -->
24-
<!-- CODE:END -->
25-
<!-- OUTPUT:START -->
26-
<!-- PLACEHOLDER --> Output is generated during CI build. We don't commit generated content to keep docs copyable and avoid recursion. See docs/docs_gen.py
27-
<!-- OUTPUT:END -->
28-
```
29-
30-
### Example 2: Multiple code blocks
31-
<!-- CODE:SKIP --> <!-- This is here otherwise the next example gets executed -->
32-
```markdown
33-
Here are two code blocks:
34-
35-
First code block:
36-
37-
<!-- CODE:START -->
38-
<!-- print('Hello, world!') -->
39-
<!-- CODE:END -->
40-
<!-- OUTPUT:START -->
41-
<!-- PLACEHOLDER --> Output is generated during CI build. We don't commit generated content to keep docs copyable and avoid recursion. See docs/docs_gen.py
42-
<!-- OUTPUT:END -->
43-
```
44-
45-
<!-- CODE:SKIP --> <!-- This is here otherwise the next example gets executed --> <!-- This is here otherwise the next example gets executed -->
46-
```markdown
47-
Second code block:
48-
49-
<!-- CODE:START -->
50-
<!-- print('Hello again!') -->
51-
<!-- CODE:END -->
52-
<!-- OUTPUT:START -->
53-
<!-- PLACEHOLDER --> Output is generated during CI build. We don't commit generated content to keep docs copyable and avoid recursion. See docs/docs_gen.py
54-
<!-- OUTPUT:END -->
55-
```
56-
57-
After running `markdown-code-runner`:
58-
59-
```markdown
60-
Here are two code blocks:
61-
62-
First code block:
63-
64-
<!-- CODE:START -->
65-
<!-- print('Hello, world!') -->
66-
<!-- CODE:END -->
67-
<!-- OUTPUT:START -->
68-
<!-- PLACEHOLDER --> Output is generated during CI build. We don't commit generated content to keep docs copyable and avoid recursion. See docs/docs_gen.py
69-
<!-- OUTPUT:END -->
70-
71-
Second code block:
72-
73-
<!-- CODE:START -->
74-
<!-- print('Hello again!') -->
75-
<!-- CODE:END -->
76-
<!-- OUTPUT:START -->
77-
<!-- PLACEHOLDER --> Output is generated during CI build. We don't commit generated content to keep docs copyable and avoid recursion. See docs/docs_gen.py
78-
<!-- OUTPUT:END -->
79-
```
80-
8115
<!-- OUTPUT:END -->
8216

8317
## Usage Ideas
@@ -98,152 +32,13 @@ Second code block:
9832
<!-- PLACEHOLDER --> Output is generated during CI build. We don't commit generated content to keep docs copyable and avoid recursion. See docs/docs_gen.py
9933
<!-- OUTPUT:END -->
10034

101-
### Idea 3: Generating Markdown Tables
102-
103-
Use the `pandas` library to create a Markdown table from a DataFrame. The following example demonstrates how to create a table with random data:
104-
105-
```python
106-
import pandas as pd
107-
import numpy as np
108-
109-
# Generate random data
110-
np.random.seed(42)
111-
data = np.random.randint(1, 101, size=(5, 3))
112-
113-
# Create a DataFrame and column names
114-
df = pd.DataFrame(data, columns=["Column A", "Column B", "Column C"])
115-
116-
# Convert the DataFrame to a Markdown table
117-
print(df.to_markdown(index=False))
118-
```
119-
120-
Which is rendered as:
121-
122-
<!-- OUTPUT:START -->
123-
<!-- PLACEHOLDER --> Output is generated during CI build. We don't commit generated content to keep docs copyable and avoid recursion. See docs/docs_gen.py
124-
<!-- OUTPUT:END -->
125-
126-
### Idea 4: Generating Visualizations
127-
128-
Create a visualization using the `matplotlib` library and save it as an image. Then, reference the image in your Markdown file. The following example demonstrates how to create a bar chart.
129-
130-
Using a triple-backtick code block:
131-
132-
<!-- CODE:SKIP --> <!-- This is here otherwise the next example gets executed -->
133-
```python
134-
import matplotlib.pyplot as plt
135-
import io
136-
import base64
137-
from urllib.parse import quote
138-
139-
# Example data for the plot
140-
x = [1, 2, 3, 4, 5]
141-
y = [2, 4, 6, 8, 10]
142-
143-
# Create a simple line plot
144-
plt.plot(x, y)
145-
plt.xlabel("X-axis")
146-
plt.ylabel("Y-axis")
147-
plt.title("Sample Line Plot")
148-
149-
# Save the plot to a BytesIO buffer
150-
buf = io.BytesIO()
151-
plt.savefig(buf, format='png')
152-
plt.close()
153-
154-
# Encode the buffer as a base64 string
155-
data = base64.b64encode(buf.getvalue()).decode('utf-8')
156-
157-
# Create an inline HTML img tag with the base64 string
158-
from urllib.parse import quote
159-
img_html = f'<img src="data:image/png;base64,{quote(data)}" alt="Sample Line Plot"/>'
160-
161-
print(img_html)
162-
```
163-
<!-- OUTPUT:START -->
164-
<!-- PLACEHOLDER --> Output is generated during CI build. We don't commit generated content to keep docs copyable and avoid recursion. See docs/docs_gen.py
165-
<!-- OUTPUT:END -->
166-
167-
> **NOTE**: This output is disabled here because GitHub Markdown doesn't support inline image HTML. This will work on other Markdown renderers.
168-
169-
### Idea 5: Generating a table from CSV data
170-
171-
Suppose you have a CSV file containing data that you want to display as a table in your Markdown file.
172-
You can use `pandas` to read the CSV file, convert it to a DataFrame, and then output it as a Markdown table.
173-
174-
Using a triple-backtick code block:
175-
176-
```python
177-
import pandas as pd
178-
csv_data = "Name,Age,Score\nAlice,30,90\nBob,25,85\nCharlie,22,95"
179-
with open("sample_data.csv", "w") as f:
180-
f.write(csv_data)
181-
df = pd.read_csv("sample_data.csv")
182-
print(df.to_markdown(index=False))
183-
```
184-
185-
Which is rendered as:
186-
187-
<!-- OUTPUT:START -->
188-
<!-- PLACEHOLDER --> Output is generated during CI build. We don't commit generated content to keep docs copyable and avoid recursion. See docs/docs_gen.py
189-
<!-- OUTPUT:END -->
190-
191-
### Idea 6: Displaying API data as a list
192-
193-
You can use `markdown-code-runner` to make API calls and display the data as a list in your Markdown file.
194-
In this example, we'll use the `requests` library to fetch data from an API and display the results as a list.
195-
196-
Using a hidden code block:
197-
198-
<!-- CODE:SKIP --> <!-- This prevents the example below from getting executed -->
199-
```markdown
200-
<!-- CODE:START -->
201-
<!-- import requests -->
202-
<!-- response = requests.get("https://jsonplaceholder.typicode.com/todos?_limit=5") -->
203-
<!-- todos = response.json() -->
204-
<!-- for todo in todos: -->
205-
<!-- print(f"- {todo['title']} (User ID: {todo['userId']}, Completed: {todo['completed']})") -->
206-
<!-- CODE:END -->
207-
<!-- OUTPUT:START -->
208-
<!-- PLACEHOLDER --> Output is generated during CI build. We don't commit generated content to keep docs copyable and avoid recursion. See docs/docs_gen.py
209-
<!-- OUTPUT:END -->
210-
211-
212-
### Idea 7: Run a Rust program
213-
214-
We can use `markdown-code-runner` to write Rust code to a file and then a hidden bash code block to run the code and display the output.
215-
216-
The code below *is actually executed*, check out the [`README.md` in plain text](https://github.com/basnijholt/markdown-code-runner/blob/main/README.md?plain=1) to see how this works.
217-
218-
```rust
219-
fn main() {
220-
println!("Hello, world!");
221-
}
222-
```
223-
224-
Which when executed produces:
225-
226-
<!-- CODE:BASH:START -->
227-
<!-- echo '```' -->
228-
<!-- rustc main.rs && ./main -->
229-
<!-- echo '```' -->
230-
<!-- CODE:END -->
231-
232-
<!-- OUTPUT:START -->
233-
<!-- PLACEHOLDER --> Output is generated during CI build. We don't commit generated content to keep docs copyable and avoid recursion. See docs/docs_gen.py
234-
<!-- OUTPUT:END -->
235-
236-
These are just a few examples of how you can use Markdown Code Runner to enhance your Markdown documents with dynamic content. The possibilities are endless!
237-
238-
<!-- OUTPUT:END -->
239-
24035
## More Ideas
24136

24237
Here are additional creative uses for `markdown-code-runner`:
24338

24439
### Auto-Generate Package Statistics
24540

246-
```python
41+
```python markdown-code-runner
24742
# Fetch package download statistics
24843
import requests
24944

@@ -254,7 +49,7 @@ print("Download statistics would appear here!")
25449

25550
### Document Your API
25651

257-
```python
52+
```python markdown-code-runner
25853
# Auto-generate API documentation from docstrings
25954
import inspect
26055
from markdown_code_runner import update_markdown_file
@@ -272,7 +67,7 @@ if doc:
27267

27368
### Include Test Results
27469

275-
```python
70+
```python markdown-code-runner
27671
# Show test coverage or test results
27772
import subprocess
27873
result = subprocess.run(
@@ -285,7 +80,7 @@ print(result.stdout)
28580

28681
### Dynamic Configuration Examples
28782

288-
```python
83+
```python markdown-code-runner
28984
# Generate configuration examples from actual defaults
29085
print("Default markers used by markdown-code-runner:")
29186
print()

0 commit comments

Comments
 (0)