No project description provided
Project description
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.
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 Distributions
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 mdast-0.2.1.tar.gz.
File metadata
- Download URL: mdast-0.2.1.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6fad71cc7241b2728982f729d7fb72ad03c2394129c21c902af3ca82f0a33ecd
|
|
| MD5 |
bb2850f0b44073bb9fc04cb488f1a703
|
|
| BLAKE2b-256 |
e096b7d0a3dfecc72cc3d28477bf3080b46f86a3000219abd0cc4785e727e903
|
File details
Details for the file mdast-0.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: mdast-0.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c5043d4a0d17c8ed5d59a9bf532ee3d8917cda4952bb66aa92a27d58a727ee0
|
|
| MD5 |
5196ce003e35f1e92cc065f21cb2d762
|
|
| BLAKE2b-256 |
5000ea8496c6c872c78b8d15eca9dbf30f34fa2ea661fc4a621ca8c91dd861cd
|
File details
Details for the file mdast-0.2.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: mdast-0.2.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c67c2820a6c2ecc3763b0df016052bc2623be27cf9f4e4929f2495380ccf6fe4
|
|
| MD5 |
358f16518cfb86a31e364cb74e3995fb
|
|
| BLAKE2b-256 |
b17df8ef5ac1a1102814d853db362c71b679cb4f4b04926359f76db2bc4926d6
|