Bindings to the very fast MD4C markdown parser.

Clients

load(path=None)

Load pre-build or custom libraries.

Parameters:path (str) – Location of the dll or dylib.

Note

Only Dawin systems are supported out of the box.

Follow the project’s instructions to build your own.

class Main(encoding=None, **options)

Class for interacting with the parser.

The options param can be flags and callbacks.

Valid callbacks are (enter/leave)_(block/span) and text.

Flags are used to (de)activate built-in derivates and extensions.

parse(value)

Parse value with callbacks.

Parsers

class Base(*args, flags=0)

Bases: abc.ABC

Source for all parsers.

For custom parsers, overwrite _leave(), _track(), and _get(). Create a _parse_(tag) method for every handled tag. All valid tags can be found in Block and Span with trailing underscores stripped.

Flags: strike_through | underline.

_track(type, data)

Simple text will be directed here.

_leave(type, info)

Exiting tags will triger this.

_get()

Should return the final result.

get(value)

Parse the value and get the result.

class Html(*args, **opts)

Bases: Base

Converts to html.

Flags: tables.

Warning

Only works with bs4 installed.

class Ansi(*args, **opts)

Bases: Base

Converts to ansi escape sequences.

Flags: no_html.

Warning

Only works with sty installed.

Details

Objects from here will be passed to callbacks as additional information.

class Attribute
Wraps strings that are outside of a normal text flow and are propagated within various detailed structures, but still may contain string portions of different types like e.g. entities.
Name Type Description
text bytes n/a
size int n/a
substr_types int n/a
substr_offsets int n/a
class Ul
Name Type Description
is_tight int Non-zero if tight list, zero if loose.
mark str Item bullet character of the list, e.g. -, +, +.
class Ol
Name Type Description
start int First index of the ordered list.
is_tight int Non-zero if tight list, zero if loose.
mark_delimiter str Character delimiting the item marks in md source, e.g. . or )
class Li
Name Type Description
is_task int Can be non-zero only with Spec’s task_lists.
task_mark str If is_task, it’s x, X or single space. None otherwise.
task_mark_offset int If is_task, offset in the input of the char between ( and ).
class H
Name Type Description
level int Header level (1 to 6)
class Code
Name Type Description
info Attribute n/a
lang Attribute The language’s syntax name.
fence_char str The character used for fenced code block; or zero for indented code block.
class Td
Name Type Description
align int n/a
class A
Name Type Description
href Attribute n/a
title Attribute n/a
class Img
Name Type Description
src Attribute n/a
title Attribute n/a
Name Type Description
target Attribute n/a

Flags

class Spec

An enumeration.

collapse_whitespace = 1
permissive_at_xheaders = 2
no_indented_code_blocks = 16
no_html_blocks = 32
no_html_spans = 64
tables = 256
strike_through = 512
task_lists = 2048
latex_math_spans = 4096
underline = 16384
no_html = 96
class Dialect

An enumeration.

commonmark = 0
github = 3852

Enums

class Block

An enumeration.

code = 7
doc = 0
h = 6
hr = 5
html = 8
li = 4
ol = 3
p = 9
quote = 1
table = 10
tbody = 12
td = 15
th = 14
thead = 11
tr = 13
ul = 2
class Span

An enumeration.

a = 2
code = 4
del_ = 5
em = 0
img = 3
latex_math = 6
latex_math_display = 7
strong = 1
u = 9
class Text

An enumeration.

br = 2
code = 5
entity = 4
html = 6
latex_math = 7
normal = 0
nullchar = 1
soft_br = 3
class Align

An enumeration.

center = 2
default = 0
left = 1
right = 3