Transform text into beautiful markdown, effortlessly.
Project description
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
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 mdfy-0.8.0.tar.gz.
File metadata
- Download URL: mdfy-0.8.0.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea1bd4bf60c302b020338a773a4ea73a43c75697ce4c37f175e49da60f671133
|
|
| MD5 |
31f66b9ef5cffff44557ed0061d50a18
|
|
| BLAKE2b-256 |
b93dc2fc70b8c907668fd22dba5874200c7376066c3da53dde38e33949c04def
|
Provenance
The following attestation bundles were made for mdfy-0.8.0.tar.gz:
Publisher:
publish.yml on argonism/mdfy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mdfy-0.8.0.tar.gz -
Subject digest:
ea1bd4bf60c302b020338a773a4ea73a43c75697ce4c37f175e49da60f671133 - Sigstore transparency entry: 220054835
- Sigstore integration time:
-
Permalink:
argonism/mdfy@9a4fa405ff202f5109d54d2f63f4da4b0ec901ce -
Branch / Tag:
refs/heads/main - Owner: https://github.com/argonism
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9a4fa405ff202f5109d54d2f63f4da4b0ec901ce -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file mdfy-0.8.0-py3-none-any.whl.
File metadata
- Download URL: mdfy-0.8.0-py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
104699b9495fb4535ecb7b25d60dd61105a8bc89988608838b43e77a7929b8d6
|
|
| MD5 |
13f53066afe3a92e80101127b2a679eb
|
|
| BLAKE2b-256 |
6feaf4a93a4342aae49d1139c8e738e05d19825684176a2df172d577c323af71
|
Provenance
The following attestation bundles were made for mdfy-0.8.0-py3-none-any.whl:
Publisher:
publish.yml on argonism/mdfy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mdfy-0.8.0-py3-none-any.whl -
Subject digest:
104699b9495fb4535ecb7b25d60dd61105a8bc89988608838b43e77a7929b8d6 - Sigstore transparency entry: 220054837
- Sigstore integration time:
-
Permalink:
argonism/mdfy@9a4fa405ff202f5109d54d2f63f4da4b0ec901ce -
Branch / Tag:
refs/heads/main - Owner: https://github.com/argonism
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9a4fa405ff202f5109d54d2f63f4da4b0ec901ce -
Trigger Event:
workflow_dispatch
-
Statement type: