Skip to main content

pymd-gadgets

Small Python-Markdown extensions that make Markdown more pleasant to write. They work anywhere Python-Markdown is used, including MkDocs and Material for MkDocs.

  • compact_lists: start a list right after a line of text, without a blank line in between.
  • yamltable: write tables as YAML instead of hand-aligning pipes.

Installation

pip install pymd-gadgets

Requires Python 3.10+. Installs Markdown and PyYAML as dependencies.

Usage

MkDocs

# mkdocs.yml
markdown_extensions:
  - tables            # needed by yamltable
  - compact_lists
  - yamltable

The full module paths pymd_gadgets.compact_lists and pymd_gadgets.yamltable work as well.

Python

import markdown

html = markdown.markdown(
    text,
    extensions=["tables", "compact_lists", "yamltable"],
)

You can also pass extension instances:

from pymd_gadgets import CompactListsExtension, YamlTableExtension

markdown.markdown(text, extensions=["tables", CompactListsExtension(), YamlTableExtension()])

compact_lists

Python-Markdown needs a blank line between a paragraph and a list.

Pros:
- Fast
- Simple

By default, this renders as a single paragraph: Pros: - Fast - Simple.

With compact_lists enabled, it renders as expected:

<p>Pros:</p>
<ul>
<li>Fast</li>
<li>Simple</li>
</ul>

It follows the CommonMark rules for lists that may interrupt a paragraph:

  • -, * and + bullet lists and ordered lists starting at 1. or 1) are recognized. A line such as 2024. was a good year stays paragraph text.
  • Multi-line items, nested lists and lazy continuation lines stay part of the same list, so the list stays tight.
  • Content inside fenced code blocks (``` or ~~~) is left alone.

yamltable

Add a #| yamltable line to a fenced yaml block (usually the first line). It is replaced with a Markdown table. The tables extension must be enabled to render the result.

The data can be written row by row under rows:

```yaml
#| yamltable
header:
  tool:
    name: Tool
    align: right
  use: Purpose

rows:
  - tool: "[MkDocs](https://www.mkdocs.org/)"
    use: Static site generator
    license: BSD-2-Clause
  - tool: "`pymd-gadgets`"
    use: Markdown extensions
    license: MIT
```

or column by column under columns:

```yaml
#| yamltable
header:
  tool:
    name: Tool
    align: right
  use: Purpose

columns:
  tool:
    - "[MkDocs](https://www.mkdocs.org/)"
    - "`pymd-gadgets`"
  use:
    - Static site generator
    - Markdown extensions
  license:
    - BSD-2-Clause
    - MIT
```

Both render as:

Tool Purpose license
MkDocs Static site generator BSD-2-Clause
pymd-gadgets Markdown extensions MIT
  • header is optional. It maps column keys to a display name, or to a mapping with name and align (left, center or right). Configured columns come first; other keys found in the data follow in order of appearance.
  • Use either rows or columns per block, not both. In column-first data, shorter columns are padded with empty cells.

Blocks without the marker are rendered as ordinary YAML code blocks.

Development

uv sync
uv run pytest

Tests are driven by fixture files in tests/fixtures/, each with an --- input --- and an --- expected --- section.

License

MIT

Release files for pymd-gadgets 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pymd-gadgets 0.2.0
File Size Uploaded
pymd_gadgets-0.2.0.tar.gz 7.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pymd-gadgets 0.2.0
File Interpreter ABI Platform
pymd_gadgets-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.9 kB

Release files / pymd_gadgets-0.2.0.tar.gz

Download URL pymd_gadgets-0.2.0.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d43f2f3ea11f0e6dda7fcfe56de22ecec35b4a2fbcf32266631be4eccdd77103
BLAKE2b-256 checksum
How to use checksums
2d03433dd2f6e597139cb67f08850e612330fe3767c1c3fe65cd91b634bf0ab6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.11

Release files / pymd_gadgets-0.2.0-py3-none-any.whl

Download URL pymd_gadgets-0.2.0-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f63fe59156ef791837c9356db875005c4bb0155c2ada469a786b74562129fac7
BLAKE2b-256 checksum
How to use checksums
2895c1a439382774154026a955d7ba74f1c200aaaf12817a5f1f9f9ae1fb9d21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.11

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page