Skip to main content

Transform text into beautiful markdown, effortlessly.

Project description



mdfy teaser

test latest version issues Documentation Status PyPI dialy downloads PyPI weekly downloads PyPI monthly downloads

mdfy

Transform text into beautiful markdown, effortlessly.

🌟 Features

  • Simplicity: Just a few lines of code and voila! An intuitive architecture made simple.
  • Modulability: Each module is highly independent, making it easy to use on its own.
  • Customizable: Extensible design allowing for easy customization.
  • Highly Tested: Robust unit tests ensure reliability.

🚀 Getting Started

Installation

pip install mdfy

Usage

Here's a quick start guide to get you up and running!

from mdfy import Mdfier, MdText, MdHeader, MdTable

contents = [
  MdHeader("Hello, MDFY!"),
  MdText("[Life:bold] is [like:italic] a bicycle."),
  MdTable({"head1": "content", "head2": "content"})
]
Mdfier("markdown.md").write(contents)

# => markdown.md
#
# # Hello, MDFY!
# **Life** is *like* a bicycle.

You can pass nested list to Mdfier.write and it will be flatterned:

from mdfy import Mdfier, MdText, MdHeader, MdTable

group = ["Group A", "Group B"]
group_agg_results = [
  [2, 3, 0, 1],
  [4, 2, 1, 0],
]

contents = [
  MdHeader("Hello, MDFY!"),
  [
    (
      MdHeader(group_name, level=2),
      MdText(f"Sum: {sum(group_agg_result)} ({', '.join(map(str, group_agg_result))})")
    )
    for group_name, group_agg_result in zip(group, group_agg_results)
  ]
]
Mdfier("markdown.md").write(contents)

# => markdown.md
# # Hello, MDFY!
# ## Group A
# Sum: 6 (2, 3, 0, 1)
# ## Group B
# Sum: 7 (4, 2, 1, 0)

Each mdfy element is string-convertible and can operate independently!

from mdfy import MdText, MdHeader, MdTable

print(MdHeader("Hello, MDFY!"))
print(MdText("[Life:bold] is [like:italic] a bicycle."))
print(MdTable({"head1": "content", "head2": "content"}))

# => result
#
# # Hello, MDFY!
# **Life** is *like* a bicycle.
# | head1 | head2 |
# | --- | --- |
# | content | content |

MdText Format

With MdText, you can flexibly specify text styles in a way similar to python's string formatting.

MdText("[a family:quote] of [plain-text formatting syntaxes:bold] that optionally can be [converted to [formal:italic] [markup languages:bold]:not] such as [HTML:strong]")

a family of plain-text formatting syntaxes that optionally can be converted to formal markup languages such as HTML

See MdText document for details

MdTable

MdTable offers a flexible way to convert a Python dict to a Markdown table.

data = [
    {"precision": 0.845, "Recall": 0.662},
    {"precision": 0.637, "Recall": 0.802},
    {"precision": 0.710, "Recall": 0.680},
]

print(MdTable(data))

# The result will be
# | precision | Recall |
# | --- | --- |
# | 0.845 | 0.662 |
# | 0.637 | 0.802 |
# | 0.71 | 0.68 |

To transpose a table, all you need to do is pass True to the transpose parameter.

print(MdTable(data, transpose=True))

# | Key | Value 0 | Value 1 | Value 2 |
# | --- | --- | --- | --- |
# | precision | 0.845 | 0.637 | 0.71 |
# | Recall | 0.662 | 0.802 | 0.68 |

# And you can specify header labels when transpose
labels = ["Metrics", "Model 1", "Model 2", "Model 3"]
print(MdTable(data, transpose=True, labels=labels))

# | Metrics | Model 1 | Model 2 | Model 3 |
# | --- | --- | --- | --- |
# | precision | 0.845 | 0.637 | 0.71 |
# | Recall | 0.662 | 0.802 | 0.68 |

You can also specify the precision of float values.

data = [
    {"precision": 0.84544, "Recall": 0.662765},
    {"precision": 0.63743, "Recall": 0.802697},
    {"precision": 0.718203, "Recall": 0.6802435},
]
labels = ["Metrics", "Model 1", "Model 2", "Model 3"]
print(MdTable(data, transpose=True, labels=labels, precision=3))

# | Metrics | Model 1 | Model 2 | Model 3 |
# | --- | --- | --- | --- |
# | precision | 0.845 | 0.637 | 0.718 |
# | Recall | 0.663 | 0.803 | 0.680 |

See MdTable document for details

📖 Documentation

Check out our full documentation for detailed guides and API references.

✅ Testing

To run the tests:

python -m pytest

💡 Contributing

We welcome contributions!

📜 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

mdfy-0.7.0.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

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

mdfy-0.7.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file mdfy-0.7.0.tar.gz.

File metadata

  • Download URL: mdfy-0.7.0.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mdfy-0.7.0.tar.gz
Algorithm Hash digest
SHA256 7b94220292e7b60c626639ff1bf1054f5c86e1bbbff45fc1a8711e11be7c7f8b
MD5 2a435f22ae490be2f4e75b4e4ac4f2a6
BLAKE2b-256 ebac5a837c4f23b8a2877c446ac31f01d2fb7896ed1cfc87211a8c3806f31dc6

See more details on using hashes here.

Provenance

The following attestation bundles were made for mdfy-0.7.0.tar.gz:

Publisher: publish.yml on argonism/mdfy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mdfy-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: mdfy-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mdfy-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 80656ce886dd48d5377bb7de2b58bb14902adcbdefdf21e3bc478cb07cdfeb89
MD5 c98b66ce41e35e28ecaf36aaf52019a0
BLAKE2b-256 e12409d13df95f92c96a97564013c6f217da085c449bfe005e069b01073505c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for mdfy-0.7.0-py3-none-any.whl:

Publisher: publish.yml on argonism/mdfy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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