A tool to generate markdown tables based on a set of files
Project description
Markdown Template
A tool to help primarily with generating Markdown tables based on a set of files. This is particularly useful to repositories that contain several subprojects, such as userscript repos.
Installation
This will install md-template
and natsort
as well as PyYAML
for the userscript preset.
pip install md-template[full]
For the most minimal installation.
pip install md-template
# or with natsort (recommended)
pip install md-template[natsort]
Usage
Command-line
The easiest but most restricted method.
# md-template --help
md-template table --preset scoop --dry-run
Class-based
See table.presets for more detailed examples.
from pathlib import Path
from typing import Iterable
from mdtemplate.table import TableTemplate
class MyTemplate(TableTemplate):
files = "bucket/*.json"
columns = ("Name", "Branch")
source = "README.md" # default
def handle_path(self, path: Path) -> Iterable[Iterable[str]]:
# create a row
yield [
# include information using the current filepath
f"Column 1: **{path.name}**",
# use information from the git repository
f"Column 2: {self.repository.branch}",
]
if __name__ == "__main__":
MyTemplate().parse_args().render()
Function-based
from pathlib import Path
from typing import Iterable
from mdtemplate.table import TableTemplate
def handle_path(self: TableTemplate, path: Path) -> Iterable[Iterable[str]]:
# create a row
yield [
# include information using the current filepath
f"Column 1: **{path.name}**",
# use information from the git repository
f"Column 2: {self.repository.branch}",
]
if __name__ == "__main__":
TableTemplate(
files="bucket/*.json",
columns=("Name", "Branch"),
source="README.md", # default
handle_path=handle_path,
).parse_args().render()
Output
Both the class-based and function-based examples above generate the same table.
Input
# My Repository
<!-- table -->
<!-- table-end -->
Output
# My Repository
<!-- table -->
| Name | Branch |
| ---- | ------ |
| Column 1: **filename.json** | Column 2: main |
<!-- table-end -->
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
md-template-0.1.1.tar.gz
(10.6 kB
view hashes)
Built Distribution
Close
Hashes for md_template-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67a172b9ca6fd18726091fde34f4a44fd8a6aa95e6c1b63b0c70027801845a6e |
|
MD5 | 94355cb42b11061c91f8a5420cd234e5 |
|
BLAKE2b-256 | 66c4cec75aef1084cfba458f0040206e5263298eb706aa8be09befeed993166b |