Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mdtidy-0.2.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mdtidy-0.2.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file mdtidy-0.2.0.tar.gz.

File metadata

  • Download URL: mdtidy-0.2.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.9

File hashes

Hashes for mdtidy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 45b6304dc3e6e78226eca50853609a49740c707f496c216d2791fac54d90fbb3
MD5 ad217642044b2b8253a8a7d264474e44
BLAKE2b-256 3bcb8b6a2de4fcb60e36a44c3687b8e63dfeb44ce55de81ff9ebaed2948c76e3

See more details on using hashes here.

File details

Details for the file mdtidy-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: mdtidy-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.9

File hashes

Hashes for mdtidy-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0bca7c6b61bb9150f6f4b0f00f52073b4cb71c89f806411480f9cbacff970d5c
MD5 e5da7784675fc77cb8bf4d197451f663
BLAKE2b-256 b2a60447439a772ff6cdb73a1d99d59f80f21a09a6d21dc2158ac13a20026056

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page