cmark.py 2.13 KB
Newer Older
1 2 3
"""Set up the shared libcmark-gfm library and extensions."""
# pylint: disable=invalid-name

4
from ctypes import c_char_p, c_int, c_size_t, c_void_p, CDLL
5 6


Deimos's avatar
Deimos committed
7
CMARK_DLL = CDLL("/usr/local/lib/libcmark-gfm.so")
Deimos's avatar
Deimos committed
8
CMARK_EXT_DLL = CDLL("/usr/local/lib/libcmark-gfm-extensions.so")
9

10 11 12 13 14 15 16 17
# Enable cmark options: --hardbreaks, --unsafe, --strikethrough-double-tilde
# Can we import these somehow? They're defined in cmark.h with the same values as below
CMARK_OPT_HARDBREAKS = 1 << 2
CMARK_OPT_UNSAFE = 1 << 17
CMARK_OPT_STRIKETHROUGH_DOUBLE_TILDE = 1 << 14
CMARK_OPTS = (
    CMARK_OPT_HARDBREAKS | CMARK_OPT_UNSAFE | CMARK_OPT_STRIKETHROUGH_DOUBLE_TILDE
)
18

19
CMARK_EXTENSIONS = (b"autolink", b"strikethrough", b"table")
20 21 22 23 24 25 26 27 28 29 30 31 32

cmark_parser_new = CMARK_DLL.cmark_parser_new
cmark_parser_new.restype = c_void_p
cmark_parser_new.argtypes = (c_int,)

cmark_parser_feed = CMARK_DLL.cmark_parser_feed
cmark_parser_feed.restype = None
cmark_parser_feed.argtypes = (c_void_p, c_char_p, c_size_t)

cmark_parser_finish = CMARK_DLL.cmark_parser_finish
cmark_parser_finish.restype = c_void_p
cmark_parser_finish.argtypes = (c_void_p,)

Deimos's avatar
Deimos committed
33
cmark_parser_attach_syntax_extension = CMARK_DLL.cmark_parser_attach_syntax_extension
34 35 36
cmark_parser_attach_syntax_extension.restype = c_int
cmark_parser_attach_syntax_extension.argtypes = (c_void_p, c_void_p)

Deimos's avatar
Deimos committed
37
cmark_parser_get_syntax_extensions = CMARK_DLL.cmark_parser_get_syntax_extensions
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
cmark_parser_get_syntax_extensions.restype = c_void_p
cmark_parser_get_syntax_extensions.argtypes = (c_void_p,)

cmark_parser_free = CMARK_DLL.cmark_parser_free
cmark_parser_free.restype = None
cmark_parser_free.argtypes = (c_void_p,)

cmark_node_free = CMARK_DLL.cmark_node_free
cmark_node_free.restype = None
cmark_node_free.argtypes = (c_void_p,)

cmark_find_syntax_extension = CMARK_DLL.cmark_find_syntax_extension
cmark_find_syntax_extension.restype = c_void_p
cmark_find_syntax_extension.argtypes = (c_char_p,)

cmark_render_html = CMARK_DLL.cmark_render_html
cmark_render_html.restype = c_char_p
cmark_render_html.argtypes = (c_void_p, c_int, c_void_p)

Deimos's avatar
Deimos committed
57
register = CMARK_EXT_DLL.cmark_gfm_core_extensions_ensure_registered
58 59 60
register.restype = None
register.argtypes = ()
register()