Skip to main content

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

mdast-0.2.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mdast-0.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

mdast-0.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

File details

Details for the file mdast-0.2.0.tar.gz.

File metadata

  • Download URL: mdast-0.2.0.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.7.4

File hashes

Hashes for mdast-0.2.0.tar.gz
Algorithm Hash digest
SHA256 10bf5af9d1100f275771613cf2e50e580784d1f52bafb90f029882d993b8b172
MD5 597e15f432fce413e4746d30d0d1fef9
BLAKE2b-256 1514a5133618eef9a98c1e4e2a538b1c410ba0aa95bb7cc58144ad85ce3168ab

See more details on using hashes here.

File details

Details for the file mdast-0.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mdast-0.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b6fa69966fbcf590afcf8b06db6d7960e35550f5d0f0c88e2adf2009d4f06680
MD5 b577a78a76066c75f7818c78809bf5f8
BLAKE2b-256 e1bbdf47aeb3dc370382dfba0cb439a304008d1783ce1fec410a1423dd707c20

See more details on using hashes here.

File details

Details for the file mdast-0.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for mdast-0.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 befa6b2fead8db502910fe8d004452bd207e21fc74e44b7fcf04a308808d1e3c
MD5 031aef6e6f689cf56f97afa9b13976ce
BLAKE2b-256 6807e9748c4f6ce1dad165034182381361f997eb3d63cf2a2980baad86ca0f57

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page