Skip to main content

A tool to generate markdown tables based on a set of files

Project description

Markdown Template

Project version Supported python versions License CodeFactor Grade Code style

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 -->
| Manifests |
| --------- |

<!-- table-end -->

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

md_template-0.2.1.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

md_template-0.2.1-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file md_template-0.2.1.tar.gz.

File metadata

  • Download URL: md_template-0.2.1.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.5.4

File hashes

Hashes for md_template-0.2.1.tar.gz
Algorithm Hash digest
SHA256 4bf30f66d8daedd4ed9aff41cd270c5519db408afb5a9299d8dda09385a7de2c
MD5 9cf47d0125694c3d1f916b173ff96017
BLAKE2b-256 65f15d4b7098453279b74ac71d265ee7d1d0cf3f16ac7b94ad90999ce66c0f47

See more details on using hashes here.

File details

Details for the file md_template-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for md_template-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f0ca17d24a3c4b5d34d3f9507b6a6e33d18198607bacf8b428fa172c9adc5bb8
MD5 f6b7098df4411730ab8771340af55746
BLAKE2b-256 e2cd3804b22270629bf68db50f8ca0d66d32c6148866a00df6e930e111c4aa70

See more details on using hashes here.

Supported by

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