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_content_to_ipynb
# Example input string
input_string = """
The columns relevant to this analysis are:
- `TotalIncome`
- `Matri_Años`
Since the column `Matri_Años` is already of type float64, it can be used as is for the numerical calculations. We will create a simple scatter plot to visualize the relationship between these two variables.
``python?code_reference&code_event_index=3
import altair as alt
# Create a simple scatter plot with `Matri_Años` on the x-axis and `TotalIncome` on the y-axis.
chart = alt.Chart(df).mark_point().encode(
x=alt.X('Matri_Años:Q', title='Years of Marriage'),
y=alt.Y('TotalIncome:Q', title='Total Income'),
tooltip=['Matri_Años', 'TotalIncome']
).properties(
title='Total Income vs. Years of Marriage'
).interactive()
# Save the plot
chart.save('total_income_vs_years_of_marriage_scatterplot.json')
``
[json-tag: vegalite_1716301077.4469488_total_income_vs_years_of_marriage_scatterplot.json]
The chart titled 'Total Income vs. Years of Marriage' displays the relationship between total income and years of marriage for all divorce records.
"""
# Convert the content to a Jupyter Notebook file
process_content_to_ipynb(input_string, "cleaned_output.ipynb")
Count Code Errors
from mdtidy.cleaner import count_code_errors
# Example input string with errors
input_string_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_string_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.1.tar.gz.
File metadata
- Download URL: mdtidy-0.2.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a52419aaf319727f19901f9648b27b81f0566b0630f0329248c0e9f7d07811cf
|
|
| MD5 |
04da00b92368a63502ddf448b9f5d153
|
|
| BLAKE2b-256 |
eaa1a57dbbed7062cd08cff521e9f47566d5e7db355b89ca84d7eef11fb2b8f0
|
File details
Details for the file mdtidy-0.2.1-py3-none-any.whl.
File metadata
- Download URL: mdtidy-0.2.1-py3-none-any.whl
- Upload date:
- Size: 4.7 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 |
cb95a1282c44cfe90827b013ab8f3e5bbe3d842138ee50b56b3d6955b94e6a49
|
|
| MD5 |
81ce6cb3eb534c0eefd3de35744abed3
|
|
| BLAKE2b-256 |
9aa2a449c6aa38be7cce204c3baf94c5c4ad80ac36d405116cea9b506bee5462
|