Format 'GitHub Markdown Alerts,' which use blockquotes to render admonitions
Project description
mdformat-gfm-alerts
An mdformat plugin for GFM Alerts. For the JS markdown-it equivalent, see antfu/markdown-it-github-alerts
Scope
By default, this package targets the alert syntax GitHub itself renders: [!NOTE], [!TIP], [!IMPORTANT], [!WARNING], and [!CAUTION] alone on their own line, per GitHub's alerts spec. Custom titles ([!TIP] Title) and fold indicators aren't part of that spec, so this package folds trailing text on the marker line into the alert body instead of treating it as a title, matching how GitHub itself would render it.
Obsidian's callout syntax (open-ended types, fold indicators, and custom titles) is where this convention originates. Hugo's alert syntax mirrors just the custom-title/fold grammar, restricted to GFM's five types. Pass --custom-title (or the custom_title option, see Configuration) to preserve an inline title on the canonical [!TYPE] line instead of folding it into the body. This package still won't support fold indicators or Obsidian's open-ended callout types. For that:
- mdformat-hugo bundles this package alongside Hugo-specific shortcode and markdown-attribute formatting
- mdformat-obsidian fully supports GFM-style alerts plus custom titles, folding, and Obsidian's open-ended callout types
Configuration
--custom-title (CLI), custom_title = true under [plugin.gfm_alerts] (.mdformat.toml), or options={"custom_title": True} (API) preserves an inline custom title on the canonical [!TYPE] line instead of folding it into the body:
<!-- Strict GFM (default): -->
> [!TIP]
> Custom title
> Body.
<!-- With --custom-title: -->
> [!TIP] Custom title
> Body.
mdformat Usage
Add this package wherever you use mdformat and the plugin will be auto-recognized. No additional configuration necessary. See additional information on mdformat plugins here
pre-commit / prek
repos:
- repo: https://github.com/executablebooks/mdformat
rev: 1.0.0
hooks:
- id: mdformat
additional_dependencies:
- mdformat-gfm-alerts
uvx
uvx --with=mdformat-gfm-alerts mdformat
Or with pipx:
pipx install mdformat
pipx inject mdformat mdformat-gfm-alerts
HTML Rendering
To generate HTML output, gfm_alerts_plugin can be imported from mdit_plugins. For more guidance on MarkdownIt, see the docs: https://markdown-it-py.readthedocs.io/en/latest/using.html#the-parser
from markdown_it import MarkdownIt
from mdformat_gfm_alerts.mdit_plugins import gfm_alerts_plugin
md = MarkdownIt()
md.use(gfm_alerts_plugin) # pass custom_title=True to preserve inline custom titles
text = """
> [!WARNING]
> This is the warning text
"""
md.render(text)
# <div class="markdown-alert markdown-alert-warning">
# <p class="markdown-alert-title">Warning</p>
# <p>This is the warning text</p>
# </div>
Contributing
See CONTRIBUTING.md
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mdformat_gfm_alerts-2.1.0.tar.gz.
File metadata
- Download URL: mdformat_gfm_alerts-2.1.0.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27673500976f08eb9e53cfa359f2a528c1be12052d3f8358996b9c5b1cc0c5c2
|
|
| MD5 |
723d842f56c01ffe208456510a7442ae
|
|
| BLAKE2b-256 |
bf1798382efef9d4a95fef60f1b5bf9e79a5f62f6698c747d2c99baacdf4cff8
|
Provenance
The following attestation bundles were made for mdformat_gfm_alerts-2.1.0.tar.gz:
Publisher:
tests.yml on KyleKing/mdformat-gfm-alerts
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mdformat_gfm_alerts-2.1.0.tar.gz -
Subject digest:
27673500976f08eb9e53cfa359f2a528c1be12052d3f8358996b9c5b1cc0c5c2 - Sigstore transparency entry: 2255533614
- Sigstore integration time:
-
Permalink:
KyleKing/mdformat-gfm-alerts@9402a56c1dea4ed93b442162df9d3fa02d08f7d0 -
Branch / Tag:
refs/tags/v2.1.0 - Owner: https://github.com/KyleKing
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
tests.yml@9402a56c1dea4ed93b442162df9d3fa02d08f7d0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mdformat_gfm_alerts-2.1.0-py3-none-any.whl.
File metadata
- Download URL: mdformat_gfm_alerts-2.1.0-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81f63efa9b2e6e343e63cdc2cede9f29c3f4c242ebc6a4d9cffeaa1b58d2a170
|
|
| MD5 |
6c357287d3c4fa35fad3faed38d44843
|
|
| BLAKE2b-256 |
17b7df953bacca701b498a616bd12be66876c9dac17fe0a44f9fed65a5b53f04
|
Provenance
The following attestation bundles were made for mdformat_gfm_alerts-2.1.0-py3-none-any.whl:
Publisher:
tests.yml on KyleKing/mdformat-gfm-alerts
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mdformat_gfm_alerts-2.1.0-py3-none-any.whl -
Subject digest:
81f63efa9b2e6e343e63cdc2cede9f29c3f4c242ebc6a4d9cffeaa1b58d2a170 - Sigstore transparency entry: 2255533677
- Sigstore integration time:
-
Permalink:
KyleKing/mdformat-gfm-alerts@9402a56c1dea4ed93b442162df9d3fa02d08f7d0 -
Branch / Tag:
refs/tags/v2.1.0 - Owner: https://github.com/KyleKing
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
tests.yml@9402a56c1dea4ed93b442162df9d3fa02d08f7d0 -
Trigger Event:
push
-
Statement type: