Skip to main content

Yet Another Markdown Only Generator

Project description

PyPI Package latest release PyPI Wheel Supported versions Supported implementations

YAMDOG

YAMDOG is toolkit for creating Markdown text using Python. Markdown is a light and relatively simple markup language.

Table of Contents

Quick start guide

Here's how you can start

The first steps

Installing

Install YAMDOG with pip

pip install yamdog

Importing

Import name is the same as install name, yamdog.

import yamdog

Using the package

There are two main things to building a Markdown document using YAMDOG

  1. Making elements
  2. Combining elements into a document

You can call str on the element directly to get the markdown source

markdown_source = str(element)

but most of the time you will compose the elements together into a document

markdown_source = str(document)

Making elements

Let's start with an empty document

document = md.Document([])

Heading

Python source

heading = md.Heading('Example heading', 4)

Markdown source

#### Example heading

Rendered result

Example heading


bolded text

some italiced text

striken text

==highlighted text==

==All styles combined==

bold_text = md.Text('bolded text', {md.BOLD})
italiced_text = md.Text('some italiced text', {md.ITALIC})
strikethrough_text = md.Text('striken text', {md.STRIKETHROUGH})
highlighted_text = md.Text('highlighted text', {md.HIGHLIGHT})
all_together = md.Text('All styles combined',
                               {md.BOLD, md.ITALIC,
                                md.STRIKETHROUGH, md.HIGHLIGHT})

Paragraph

Python source

paragraph = md.Paragraph(['Example paragraph containing ',
                          md.Text('bolded text', {md.BOLD})])

Markdown source

Example paragraph containing **bolded text**

Rendered result

Example paragraph containing bolded text


Table

Python source

table = md.Table([['a', 1, 'Python'],
                  ['b', 2, 'Markdown']],
                 ['First column', 'Second column', 'Third column'],
                 [md.RIGHT, md.LEFT, md.CENTER])

Markdown source

| First column | Second column | Third column |
| -----------: | :------------ | :----------: |
|            a | 1             |    Python    |
|            b | 2             |   Markdown   |

Rendered result

First column Second column Third column
a 1 Python
b 2 Markdown

You can select compact mode at the table object creation

Compact table

Python source

table = md.Table([['a', 1, 'Python'],
                  ['b', 2, 'Markdown']],
                 ['First column', 'Second column', 'Third column'],
                 [md.RIGHT, md.LEFT, md.CENTER],
                 True)

Markdown source

First column|Second column|Third column
--:|:--|:-:
a|1|Python
b|2|Markdown

Rendered result

First column Second column Third column
a 1 Python
b 2 Markdown

or later by changing the attribute compact

table.compact = True

Listing

Python source

listing = md.Listing(['Just normal text',
                      md.Text('some stylised text', {md.ITALIC}),
                      md.Checkbox('Listings can include checkboxes', False),
                      md.Checkbox('Checked and unchecked option available', True),
                      ('Sublist by using a tuple',
                        md.Listing(['first', 'second'], md.ORDERED))],
                      md.UNORDERED)

Markdown source

- Just normal text
- *some stylised text*
- [ ] Listings can include checkboxes
- [x] Checked and unchecked option available
- Sublist by using a tuple
    1. first
    2. second

Rendered result

  • Just normal text
  • some stylised text
  • Listings can include checkboxes
  • Checked and unchecked option available
  • Sublist by using a tuple
    1. first
    2. second

Checklist

Python source

checklist = md.make_checklist([('unchecked box', False),
                               ('checked box', True),
                               ('done', True)])

Markdown source

- [ ] unchecked box
- [x] checked box
- [x] done

Rendered result

  • unchecked box
  • checked box
  • done

Link

Python source

link = md.Link('https://www.markdownguide.org', 'Link to Markdown Guide')

Markdown source

[Link to Markdown Guide](https://www.markdownguide.org)

Rendered result

Link to Markdown Guide


Codeblock

Python source

codeblock = md.CodeBlock('import yamdog as md\n\ndoc = md.Document([])',
                         'python')

Markdown source

```python
import yamdog as md

doc = md.Document([])
```

Rendered result

import yamdog as md

doc = md.Document([])

Code

Python source

code = md.Code('python != markdown')

Markdown source

`python != markdown`

Rendered result

python != markdown


Address

Python source

address = md.Link('https://www.markdownguide.org')

Markdown source

<https://www.markdownguide.org>

Rendered result

https://www.markdownguide.org


Quote block

Python source

quoteblock = md.Quote('Quote block supports\nmultiple lines')

Markdown source

> Quote block supports
> multiple lines

Rendered result

Quote block supports multiple lines


Combining elements into a document

Initialising Document with list of elements

document = md.Document([heading, link, paragraph, listing])

adding elements into a document

document = md.Document([])
document += heading
document += link
document += paragraph
document += listing

adding elements together into a document

document = heading + link + paragraph + listing

Adding two documents together

document1 = md.Document([heading, link])
document2 = md.Document([paragraph, listing])
document = document1 + document2

Markdown source

#### Example heading

[Link to Markdown Guide](https://www.markdownguide.org)

Example paragraph containing **bolded text**

- Just normal text
- *some stylised text*
- [ ] Listings can include checkboxes
- [x] Checked and unchecked option available
- Sublist by using a tuple
    1. first
    2. second

Rendered result

Example heading

Link to Markdown Guide

Example paragraph containing bolded text

  • Just normal text
  • some stylised text
  • Listings can include checkboxes
  • Checked and unchecked option available
  • Sublist by using a tuple
    1. first
    2. second

Further reading

Changelog

0.6.0 2024-07-16

Deprecations

  • python 3.9

Features

  • support for pythonn 3.13

0.5.0 2023-05-07

  • Some API changes
  • Added Raw, PDF, Comment

0.4.0 2023-01-23

  • Much better type validation
  • Some comparisons

0.3.1 2023-01-23

  • Preliminary type validation
  • Full test coverage

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

yamdog-0.6.0.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

yamdog-0.6.0-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file yamdog-0.6.0.tar.gz.

File metadata

  • Download URL: yamdog-0.6.0.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for yamdog-0.6.0.tar.gz
Algorithm Hash digest
SHA256 801054195f569c6e19aaa263b8f06350dd6cb7a790bae05026822e91352e0dc7
MD5 76633ff1e52750803e9cb4cde0470c8c
BLAKE2b-256 f814a3e3b1117a184203ff91b828b1edc1e67f48fef6c706b506fe0957b7334d

See more details on using hashes here.

File details

Details for the file yamdog-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: yamdog-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for yamdog-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d0f5a1f54a68e972d380c0458e08a36806b7964fda4a5c8a280a54637208c6c
MD5 b72bd4b59cb23e205cdfea0419434baa
BLAKE2b-256 828d1f2fb319d707596a07f1135bd5e35d4ebc3587060abb1a3ad2b4c8a98ef1

See more details on using hashes here.

Supported by

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