mdast.py
Simple Python bindings for the mdast functionality of wooorm/markdown-rs
Installation
pip install mdast
If you're on x86-64/AMD64 or arm64/aarch64, you can install this package without having Rust on your system. For other platforms, the Rust toolchain is required to build the binary dependencies.
Usage
Converting from Markdown to mdast's AST format
import mdast
mdast.md_to_ast("# title")
# -> {'type': 'root', 'children': [{'type': 'heading', 'children': [{'type': 'text', 'value': 'title'}], 'depth': 1}]}
Converting from Markdown to mdast's JSON format
import mdast
mdast.md_to_json("# title")
# -> '{"type": "root", "children": [{"type": "heading", "children": [{"type": "text", "value": "title"}], "depth": 1}]}'
Converting from mdast AST to Markdown
import mdast
ast = {'type': 'root', 'children': [{'type': 'heading', 'children': [{'type': 'text', 'value': 'title'}], 'depth': 1}]}
mdast.ast_to_md(ast)
# -> '# title\n'
Converting from mdast JSON to Markdown
import mdast
json_str = '{"type": "root", "children": [{"type": "heading", "children": [{"type": "text", "value": "title"}], "depth": 1}]}'
mdast.json_to_md(json_str)
# -> '# title\n'
Converting from Markdown to HTML
import mdast
mdast.md_to_html("# title")
# -> '<h1>title</h1>'
Converting from mdast AST to HTML
import mdast
ast = {'type': 'root', 'children': [{'type': 'heading', 'children': [{'type': 'text', 'value': 'title'}], 'depth': 1}]}
mdast.ast_to_html(ast)
# -> '<h1>title</h1>'
Converting from mdast JSON to HTML
import mdast
json_str = '{"type": "root", "children": [{"type": "heading", "children": [{"type": "text", "value": "title"}], "depth": 1}]}'
mdast.json_to_html(json_str)
# -> '<h1>title</h1>'
Configuration Options
Parsing Options
The ParseOptions class allows customization of Markdown parsing behavior:
from mdast import ParseOptions
default_options = ParseOptions(
# you can specify overwrites here
frontmatter=True,
)
gfm_options = ParseOptions.gfm()
mdx_options = ParseOptions.mdx()
Markdown Generation Options
The MarkdownOptions class customizes how Markdown is generated:
from mdast import MarkdownOptions
options = MarkdownOptions(fences=False, emphasis="_")
Note that the Markdown generation of wooorm/markdown-rs does not support MDX or GFM generation.
HTML Generation Options
The GenerationOptions class customizes how HTML is generated:
from mdast import GenerationOptions
options = GenerationOptions(allow_dangerous_html=True)
License
This project is licensed under the MIT License.
Metadata
Release files for mdast 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mdast-0.2.1.tar.gz | 10.2 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mdast-0.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.8 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| mdast-0.2.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.8 | abi3 | Linux glibc 2.17+ ARM64 | Details |
Total release size: 2.7 MB
Release files / mdast-0.2.1.tar.gz
| Download URL | mdast-0.2.1.tar.gz |
|---|---|
| Size | 10.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6fad71cc7241b2728982f729d7fb72ad03c2394129c21c902af3ca82f0a33ecd
|
|
BLAKE2b-256 checksum How to use checksums |
e096b7d0a3dfecc72cc3d28477bf3080b46f86a3000219abd0cc4785e727e903
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.8.3
|
Release files / mdast-0.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | mdast-0.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.4 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
7c5043d4a0d17c8ed5d59a9bf532ee3d8917cda4952bb66aa92a27d58a727ee0
|
|
BLAKE2b-256 checksum How to use checksums |
5000ea8496c6c872c78b8d15eca9dbf30f34fa2ea661fc4a621ca8c91dd861cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.8.3
|
Release files / mdast-0.2.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | mdast-0.2.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
c67c2820a6c2ecc3763b0df016052bc2623be27cf9f4e4929f2495380ccf6fe4
|
|
BLAKE2b-256 checksum How to use checksums |
b17df8ef5ac1a1102814d853db362c71b679cb4f4b04926359f76db2bc4926d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.8.3
|