MCPcopy Create free account
hub / github.com/commonmark/cmark / to_html

Function to_html

test/cmark.py:19–35  ·  view source on GitHub ↗
(lib, text)

Source from the content-addressed store, hash-verified

17 return [p1.returncode, result.decode('utf-8'), err]
18
19def to_html(lib, text):
20 get_alloc = lib.cmark_get_default_mem_allocator
21 get_alloc.restype = POINTER(cmark_mem)
22 free_func = get_alloc().contents.free
23
24 markdown = lib.cmark_markdown_to_html
25 markdown.restype = POINTER(c_char)
26 markdown.argtypes = [c_char_p, c_size_t, c_int]
27
28 textbytes = text.encode('utf-8')
29 textlen = len(textbytes)
30 # 1 << 17 == CMARK_OPT_UNSAFE
31 cstring = markdown(textbytes, textlen, 1 << 17)
32 result = string_at(cstring).decode('utf-8')
33 free_func(cstring)
34
35 return [0, result, '']
36
37def to_commonmark(lib, text):
38 get_alloc = lib.cmark_get_default_mem_allocator

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected