Skip to main content

A library to convert YAML files to Markdown format.

Project description

YAML to Markdown Converter

A Python utility to take a JSON / YAML file or a python dict / list and create a Markdown file.

Installation

pip install yaml-to-markdown

Usage

$ yaml-to-markdown --help
Convert JSON or YAML to Markdown.
Usage: yaml-to-markdown -o <output_file> [-y <yaml_file> | -j <json_file>]
    -o, --output-file <output_file>: Path to the output file as a string [Mandatory].
    -y, --yaml-file <yaml_file>: Path to the YAML file as a string [Optional]
    -j, --json-file <json_file>: Path to the JSON file as a string [Optional]
    -h, --help: Show this message and exit.
Note: Either yaml_file or json_file is required along with output_file.
Example: yaml-to-markdown -o output.md -y data.yaml

In Python Code example:

Convert a Pyton dictionary to Markdown:

from yaml_to_markdown.md_converter import MDConverter

data = {
    "name": "John Doe",
    "age": 30,
    "city": "Sydney",
    "hobbies": ["reading", "swimming"],
}
converter = MDConverter()
with open("output.md", "w") as f:
    converter.convert(data, f)

Content of output.md file will be:

## Name
John Doe
## Age
30
## City
Sydney
## Hobbies
* reading
* swimming

From the Command Line

You can also use the command line interface to convert a JSON or YAML file to Markdown. Here's an example:

Convert a JSON file to Markdown:

yaml-to-markdown --output-file output.md --json-file test.json

Convert a YAML file to Markdown:

yaml-to-markdown --output-file output.md --yaml-file test.yaml

YAML Conversion Examples

Simple Key-Value Pairs

Input YAML:

name: John Doe
age: 30
city: Sydney

Output Markdown:

## Name
John Doe
## Age
30
## City
Sydney

Lists

Input YAML:

hobbies:
  - reading
  - swimming
  - cycling

Output Markdown:

## Hobbies
* reading
* swimming
* cycling

Tables (List of Dictionaries)

Input YAML:

employees:
  - name: Alice
    role: Developer
    department: Engineering
  - name: Bob
    role: Designer
    department: Creative

Output Markdown:

## Employees
| Name | Role | Department |
| --- | --- | --- |
| Alice | Developer | Engineering |
| Bob | Designer | Creative |

Nested Structures

Input YAML:

company:
  name: Tech Corp
  location: Sydney
  departments:
    engineering: 50
    sales: 30

Output Markdown:

## Company
### Name
Tech Corp
### Location
Sydney
### Departments
#### Engineering
50
#### Sales
30

Images and Links

Input YAML:

logo: company-logo.png
website: https://example.com
documentation: ./docs/guide.md

Output Markdown:

![Logo](company-logo.png)

[Website](https://example.com)

[Documentation](./docs/guide.md)

Note: Files are only converted to links if they exist and are accessible. Invalid files, missing files, or files with permission errors are treated as normal text.

Developer Guide

Please see the DEVELOPER.md file for more information on how to contribute to this project.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

yaml_to_markdown-0.1.1772518140.tar.gz (581.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yaml_to_markdown-0.1.1772518140-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file yaml_to_markdown-0.1.1772518140.tar.gz.

File metadata

  • Download URL: yaml_to_markdown-0.1.1772518140.tar.gz
  • Upload date:
  • Size: 581.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for yaml_to_markdown-0.1.1772518140.tar.gz
Algorithm Hash digest
SHA256 4805f2bab315286ec75a8816abdb7db1ace2b5b8765c2f43272c3575ba2a9472
MD5 f0ce515830397ea4b45a8818e4d86c8c
BLAKE2b-256 dd36b412e31c61fd1bf0da5781a0c494c588b7bf6184adcc0b2014bca880e27a

See more details on using hashes here.

File details

Details for the file yaml_to_markdown-0.1.1772518140-py3-none-any.whl.

File metadata

  • Download URL: yaml_to_markdown-0.1.1772518140-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for yaml_to_markdown-0.1.1772518140-py3-none-any.whl
Algorithm Hash digest
SHA256 a79a1d5e4596a7ea16df269850434934f86b2bf8e89cf7551203dcd375a50d84
MD5 e8bf48fe3aac852295580aedbeb80df4
BLAKE2b-256 691e147069b0b48c218f1c61f17c537c6f944a5f0b0eb23ae8d07d83ad91604a

See more details on using hashes here.

Supported by

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