t-python-markdown
A simple to use markdown generator for Python.
Installation
pip install t-python-markdown
Example
from t_python_markdown import Document, Header, Paragraph, Sentence, Bold, Table, UnorderedList
import time
import requests
j = requests.get("https://api.coindesk.com/v1/bpi/currentprice.json").json()
bpi = j["bpi"]
front_matter = {
"title": j["chartName"],
"authors": ["A.U.Thor"],
"date": time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()),
}
doc = Document(front_matter)
doc >> Header(j["chartName"], 1)
doc >> Paragraph([j["disclaimer"]])
al = [("--:" if isinstance(_, (int, float)) else ":-:" if _.startswith("&") else ":--") for _ in bpi[list(bpi.keys())[0]].values()]
t = Table([_.replace("_", " ").title() for _ in bpi[list(bpi.keys())[0]].keys()], alignment=al)
doc >> t
ul = UnorderedList()
doc >> Paragraph("Bitcoin Price Index")
doc >> ul
for k, v in bpi.items():
t >> [_ for _ in bpi[k].values()]
ul >> Sentence([Bold(k), bpi[k]["description"]])
# Write markdown to file
doc.write("example.md")
Saved as example.py then running python example.py results in:
---
title: Bitcoin
authors:
- A.U.Thor
date: '2023-02-25T14:17:02Z'
...
# Bitcoin
This data was produced from the CoinDesk Bitcoin Price Index (USD). Non-USD currency data converted using hourly conversion rate from openexchangerates.org
| **Code** | **Symbol** | **Rate** | **Description** | **Rate Float** |
| :-- | :-: | :-- | :-- | --: |
| USD | $ | 23,007.6135 | United States Dollar | 23007.6135 |
| GBP | £ | 19,224.9778 | British Pound Sterling | 19224.9778 |
| EUR | € | 22,412.7746 | Euro | 22412.7746 |
Bitcoin Price Index
- **USD** United States Dollar.
- **GBP** British Pound Sterling.
- **EUR** Euro.
Usage
For usage, see https://www.cix.co.uk/~toyne/t-python-markdown/usage/
Recent Changelog
1.4.1
- Resolve issue where embedding tables in lists in tables in lists in tables (etc...) would not render correctly
1.4.0
- Improve support for embedded lists and tables. Now able to wrap child items in other markdown elements
1.3.2
- Add support for attribute lists when processing embedded lists
1.3.1
- Add support for attribute lists when processing embedded tables
1.3.0
- Add support for tables and lists embedded in other tables and lists
1.2.1
- Bring into line with docs site
1.2.0
- Add support for Strikethrough
Release files for t-python-markdown 1.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| t_python_markdown-1.4.1.tar.gz | 8.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| t_python_markdown-1.4.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:16.6 kB
Release files / t_python_markdown-1.4.1.tar.gz
| Download URL | t_python_markdown-1.4.1.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f6541c03d9a53fb6521e8ac27b5fd57225ec2b773b38b6717736033e5ebd649
|
|
BLAKE2b-256 checksum How to use checksums |
355a9b02308c3575aca1a8aa2332044be0510bff0a66bd611661b60784b0e473
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Release files / t_python_markdown-1.4.1-py3-none-any.whl
| Download URL | t_python_markdown-1.4.1-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
64c9cc1b88abbb41d77b4811b5dff775f1ee8ef7ff91889ebba83a2a48643aa6
|
|
BLAKE2b-256 checksum How to use checksums |
583be04cf490060f74168e0cd0448a4536032baf905b62b7d93e1d57eeec6964
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|