Skip to main content

A Python interface to pulldown-cmark.

Project description

pulldown-cmark-py

An easy-to-use, configurable Python wrapper around pulldown-cmark.

Installation

uv add "git+https://git.sr.ht/~orchid/pulldown-cmark-py"

Usage

pulldown-cmark-py provides just one function.

def render(markdown: list[str], options: Options | None = None) -> list[str]: ...

The Options class configures callbacks and CommonMark extensions; see help(Options) for details.

class Options:
    tables: bool
    footnotes: bool
    strikethrough: bool
    tasklists: bool
    smart_punctuation: bool
    heading_attributes: bool
    yaml_style_metadata_blocks: bool
    pluses_delimited_metadata_blocks: bool
    old_footnotes: bool
    gfm: bool
    definition_list: bool
    superscript: bool
    subscript: bool
    wikilinks: bool
    math: Callable[[str, bool], str] | None
    code: Callable[[str, str | None], str] | None

Simple callback examples are given below.

from latex2mathml.converter import convert
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import get_lexer_by_name, guess_lexer

def math_callback(buffer: str, display: bool) -> str:
    return convert(buffer, "display" if display else "inline")

def code_callback(buffer: str, language: str | None) -> str:
    lexer = get_lexer_by_name(language) if language else guess_lexer(buffer)
    return highlight(buffer, lexer, HtmlFormatter())

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

pulldown_cmark-0.1.0.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

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

pulldown_cmark-0.1.0-cp313-cp313-macosx_11_0_arm64.whl (413.2 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

Details for the file pulldown_cmark-0.1.0.tar.gz.

File metadata

  • Download URL: pulldown_cmark-0.1.0.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for pulldown_cmark-0.1.0.tar.gz
Algorithm Hash digest
SHA256 22a3d484a4d9e88c211b3902e7b490a0dae5b65c3a2cf292d2dcbd3ac104faaf
MD5 49ecfdcb1bbf54fb32a89cbd19397679
BLAKE2b-256 9a522e1d94d077376584dc923f00f1c4718ca0088d9a87854a6b29201dff4bb8

See more details on using hashes here.

File details

Details for the file pulldown_cmark-0.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pulldown_cmark-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b54445809cc4c31d9ff77dc99ff3101cf5ecf651ada35790a48dfd4ec875159c
MD5 7954a061361555ce5ebf255a07dbc061
BLAKE2b-256 ee27241bad303777157f3c8e6aa31027527a6b38d0f1374c387296a2023c4e9a

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