Git Product home page Git Product logo

md-template's Introduction

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 -->
<!-- table-end -->

Output

# My Repository

<!-- table -->
| Name | Branch |
| ---- | ------ |
| Column 1: **filename.json** | Column 2: main |
<!-- table-end -->

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.