A Python library to clean and format markdown content into Jupyter Notebooks.
Project description
mdtidy
mdtidy is a Python library designed to clean and format markdown content into Jupyter Notebooks (.ipynb) and count code errors within the content. It's an intuitive tool for transforming raw markdown and code blocks into well-structured Jupyter notebooks.
Features
- Markdown to Jupyter Notebook: Convert markdown content with embedded Python code blocks into a Jupyter Notebook file.
- Error Counting: Identify and count common Python error types within the content.
Installation
You can install mdtidy via pip:
pip install mdtidy
Usage
Convert Markdown to Jupyter Notebook
from mdtidy.cleaner import process_contents_to_ipynb
# Example input strings
input_string =
"""
```python?code_reference&code_event_index=1
import pandas as pd
# Read the CSV file into a DataFrame
df = pd.read_csv('data.csv')
# Display the first 5 rows
print(df.head())
col1 col2 col3
0 1 4 7
1 2 5 8
2 3 6 9
"""
input_string_2 = """
import matplotlib.pyplot as plt
# Sample data
x = [1, 2, 3, 4, 5]
y = [10, 20, 25, 30, 40]
# Create a simple line plot
plt.plot(x, y)
plt.title('Sample Line Plot')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.show()
<Figure size 432x288 with 1 Axes>
"""
input_string_3 = """
import numpy as np
# Generate an array of 10 random numbers
random_numbers = np.random.rand(10)
# Print the array
print(random_numbers)
[0.37454012 0.95071431 0.73199394 0.59865848 0.15601864 0.15599452
0.05808361 0.86617615 0.60111501 0.70807258]
"""
# Convert the content to a Jupyter Notebook file
input_strings = [input_string, input_string_2, input_string_3]
process_contents_to_ipynb(input_strings, "cleaned_output.ipynb")
Count Code Errors
from mdtidy.cleaner import count_code_errors
# Example input strings with errors
input_strings_with_errors = [
"""
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'variable' is not defined
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'
"""
]
# Count the code errors
error_counts = count_code_errors(input_strings_with_errors)
print(error_counts)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mdtidy-0.2.2.tar.gz.
File metadata
- Download URL: mdtidy-0.2.2.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
526bc61a2a0ad21d2592fe954587a9a863741601dc41b665aee40b6a34993752
|
|
| MD5 |
87861535dd168bb646f0b434161b1c44
|
|
| BLAKE2b-256 |
b5e0fa6403ed88ea4d60388bdaa79a883d6a90ddaff99e21a7526ae5c2d0ab29
|
File details
Details for the file mdtidy-0.2.2-py3-none-any.whl.
File metadata
- Download URL: mdtidy-0.2.2-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05e393b02cd6ea41752827d00836e1ccdc1f764e3ea6b6ad8a462869bd430bea
|
|
| MD5 |
b64cd436e0aeb20d21951c94da93aa7d
|
|
| BLAKE2b-256 |
b8c7735797ce35f4a394fc5b2edfc329d84f9f720aac3af512a5b5e38fd8d444
|