Last active
June 18, 2026 22:48
-
-
Save ewjoachim/e4dbcee9e2dfe5d9f9cc970b1f4b1a82 to your computer and use it in GitHub Desktop.
Remove admonition from Markdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env -S uv run --script | |
| # /// script | |
| # dependencies = [ | |
| # "markdown-it-py", | |
| # "mdformat", | |
| # "mdformat-gfm-alerts", | |
| # ] | |
| # /// | |
| import os | |
| import pathlib | |
| import markdown_it | |
| from markdown_it.tree import SyntaxTreeNode | |
| from mdformat.renderer import MDRenderer | |
| import mdformat_gfm_alerts.plugin as alerts_plugin | |
| # Parse | |
| workspace = pathlib.Path(os.environ['GITHUB_WORKSPACE']) | |
| readme_path = workspace / 'README_.md' | |
| parser = markdown_it.MarkdownIt('commonmark') | |
| alerts_plugin.update_mdit(parser) | |
| root = SyntaxTreeNode(parser.parse(readme_path.read_text())) | |
| # Mutate | |
| for node in root.walk(): | |
| if node.type == 'gfm_alert' and node.parent: | |
| node.parent.children.remove(node) | |
| break | |
| # Round-trip | |
| options = dict(parser.options) | |
| options.setdefault("parser_extension", []).append(alerts_plugin) | |
| result = MDRenderer().render(root.to_tokens(), options=options, env={}) | |
| readme_path.write_text(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment