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.

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

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

renders as:

Tool Purpose license
MkDocs Static site generator BSD-2-Clause
pymd-gadgets Markdown extensions MIT

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.1.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.1.0
File Size Uploaded
pymd_gadgets-0.1.0.tar.gz 6.8 kB Details

Built distribution (wheel)

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

Total release size: 15.5 kB

Release files / pymd_gadgets-0.1.0.tar.gz

Download URL pymd_gadgets-0.1.0.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c6019663fd4fbd31f67ac152a94c16a0d5394cd4bf0701153b87dd3eec84e84e
BLAKE2b-256 checksum
How to use checksums
3b77e27676cf8b0e02f8523543b80343704b71628c912cb1650d6d9eab10c9d7
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.1.0-py3-none-any.whl

Download URL pymd_gadgets-0.1.0-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9f34f2ff68881041caaf6b9c13640f794e752030ef1f0c361ec60e8de88b9313
BLAKE2b-256 checksum
How to use checksums
fdde51d995265f06a2f4f754f81d44f2c4d35d412a292252b74a6c13ad9f9f5b
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

0.2.0

2 release files

This release

0.1.0 This release

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