GithubHelp home page GithubHelp logo

md_jinja's Introduction

md_jinja

Description

This tool is designed to render Markdown files using templates and variable substitution. It uses Jinja2 for templating and allows variables to be defined in YAML files. This enables dynamic content generation in Markdown documents, adhering to the DRY (Don't Repeat Yourself) principle.

Requirements

  • Python 3.6 or higher
  • Jinja2
  • PyYAML

Installation

To install the required dependencies, run:

pip install Jinja2 PyYAML

Usage

  1. Prepare Your Templates:

    Create Markdown templates with placeholders for variables. Placeholders should be enclosed in double curly braces {{ }}.

    For example, create a file named greeting_template.md:

    # Greeting
    
    Hello, {{ name }}!
    
    Welcome to our service. We hope you enjoy your experience.

    And another named event_announcement_template.md:

    # Upcoming Event
    
    {{ event_name }}
    
    Get ready for the exciting event on {{ event_date }}. Don't miss out on the fun!
    
    Best regards,
    {{ organizer_name }}
  2. Define Your Variables:

    Create a YAML file with the necessary variables. For example, variables.yaml:

    name: John Doe
    event_name: Annual Tech Conference
    event_date: July 10, 2024
    organizer_name: TechCorp Inc.
  3. Run the Script:

    Execute the script by specifying the paths to the template directory, the variable directory, and the output directory.

    python render_md.py path/to/template_dir path/to/variable_dir path/to/output_dir

    If you have multiple variable directories, separate them with a semicolon ;.

    python render_md.py path/to/template_dir "path/to/variable_dir1;path/to/variable_dir2" path/to/output_dir

    The script will process each Markdown template, substituting the variables with values from the YAML files, and save the rendered documents in the specified output directory.

Example

Given the above templates and variables, running the script with the correct paths will generate Markdown files with the substituted content.

For instance, greeting_template.md will be rendered as:

# Greeting

Hello, John Doe!

Welcome to our service. We hope you enjoy your experience.

And event_announcement_template.md will be rendered as:

# Upcoming Event

Annual Tech Conference

Get ready for the exciting event on July 10, 2024. Don't miss out on the fun!

Best regards,
TechCorp Inc.

License

This project is licensed under the MIT License.

md_jinja's People

Contributors

sudodo avatar

Watchers

 avatar

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.