| 17 | return [p1.returncode, result.decode('utf-8'), err] |
| 18 | |
| 19 | def 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 | |
| 37 | def to_commonmark(lib, text): |
| 38 | get_alloc = lib.cmark_get_default_mem_allocator |