You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardExpand all lines: docs/examples.md
+4-209Lines changed: 4 additions & 209 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,72 +12,6 @@ Real-world examples demonstrating the power and flexibility of `markdown-code-ru
12
12
<!-- CODE:END -->
13
13
<!-- OUTPUT:START -->
14
14
<!-- 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
-
81
15
<!-- OUTPUT:END -->
82
16
83
17
## Usage Ideas
@@ -98,152 +32,13 @@ Second code block:
98
32
<!-- 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
99
33
<!-- OUTPUT:END -->
100
34
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:
<!-- 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.
<!-- 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 -->
<!-- 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
-
fnmain() {
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
-
240
35
## More Ideas
241
36
242
37
Here are additional creative uses for `markdown-code-runner`:
243
38
244
39
### Auto-Generate Package Statistics
245
40
246
-
```python
41
+
```python markdown-code-runner
247
42
# Fetch package download statistics
248
43
import requests
249
44
@@ -254,7 +49,7 @@ print("Download statistics would appear here!")
254
49
255
50
### Document Your API
256
51
257
-
```python
52
+
```python markdown-code-runner
258
53
# Auto-generate API documentation from docstrings
259
54
import inspect
260
55
from markdown_code_runner import update_markdown_file
@@ -272,7 +67,7 @@ if doc:
272
67
273
68
### Include Test Results
274
69
275
-
```python
70
+
```python markdown-code-runner
276
71
# Show test coverage or test results
277
72
import subprocess
278
73
result = subprocess.run(
@@ -285,7 +80,7 @@ print(result.stdout)
285
80
286
81
### Dynamic Configuration Examples
287
82
288
-
```python
83
+
```python markdown-code-runner
289
84
# Generate configuration examples from actual defaults
290
85
print("Default markers used by markdown-code-runner:")
0 commit comments