Yet Another Markdown Only Generator
Project description
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
- Making elements
- 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
- first
- 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
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
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
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
- first
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 801054195f569c6e19aaa263b8f06350dd6cb7a790bae05026822e91352e0dc7 |
|
MD5 | 76633ff1e52750803e9cb4cde0470c8c |
|
BLAKE2b-256 | f814a3e3b1117a184203ff91b828b1edc1e67f48fef6c706b506fe0957b7334d |
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d0f5a1f54a68e972d380c0458e08a36806b7964fda4a5c8a280a54637208c6c |
|
MD5 | b72bd4b59cb23e205cdfea0419434baa |
|
BLAKE2b-256 | 828d1f2fb319d707596a07f1135bd5e35d4ebc3587060abb1a3ad2b4c8a98ef1 |