marktripy¶
marktripy turns Markdown text into a tree of Python objects, lets you change that tree, and writes it back out as Markdown or HTML. The PyPI package is called marktripy; the source lives in the vexyart/vexy-marktripy repository.
from marktripy.core.parser import ParserRegistry
from marktripy.parsers import markdown_it # importing the module registers the parser
from marktripy.renderers.markdown import MarkdownRenderer
parser = ParserRegistry.create("markdown-it")
doc = parser.parse("# Hello\n\nThis is **bold** text.\n")
for node in doc.find_all("heading"):
node.level += 1
print(MarkdownRenderer().render(doc))
# ## Hello
#
# This is **bold** text.
What the package does¶
Every operation follows the same three stages:
- Parse. A parser adapter reads Markdown text and builds a
Documentnode. Two adapters ship with the package: one built onmarkdown-it-pyand one built onmistletoe. - Change. You edit the tree directly, or you run transformers (heading level changes, heading IDs, a table of contents, reference-style links) and extensions (strikethrough, task lists,
++key++keyboard notation). - Render. A renderer walks the tree and produces text.
MarkdownRendererwrites Markdown,HTMLRendererwrites HTML.
All three stages share one node model, described in The AST. Because both parsers produce the same node types, a transformer or renderer does not need to know which parser built the tree.
Project status¶
The package is at an early stage (Development Status :: 3 - Alpha in pyproject.toml). The core parse → change → render loop works and is covered by the test suite, but some parts are incomplete:
- There is no top-level convenience API. You import classes from their modules, for example
marktripy.core.parser.ParserRegistry. The namesparse_markdown,render_markdownandmarkdown_to_htmlshown in older README examples do not exist. - There is no command-line tool.
- Several behaviours have known gaps, for example table bodies from the
markdown-itadapter and[[TOC]]marker replacement. See Known limitations before you rely on a feature.
Where to go next¶
| If you want to… | Read |
|---|---|
| Install the package | Installation |
| Run a first parse and render | Quickstart |
| Understand the node classes and tree methods | The AST |
| Choose and configure a parser | Parsers |
| Control Markdown or HTML output | Renderers |
| Shift headings, add IDs, build a TOC | Transformers |
Add strikethrough, task lists or ++key++ |
Extensions |
| Check a tree for structural problems | Validation and utilities |
| Look up a class or function | API reference |
| See how the modules fit together | Architecture |
| Run the tests or build the docs | Contributing |