mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
[cmark] Add wrappers.
This commit is contained in:
Vendored
+19
-5
@@ -106,12 +106,16 @@ foreign lib {
|
|||||||
markdown_to_html :: proc(text: cstring, length: c.size_t, options: Options) -> (html: cstring) ---
|
markdown_to_html :: proc(text: cstring, length: c.size_t, options: Options) -> (html: cstring) ---
|
||||||
}
|
}
|
||||||
|
|
||||||
|
markdown_to_html_from_string :: proc(text: string, options: Options) -> (html: string) {
|
||||||
|
return string(markdown_to_html(cstring(raw_data(text)), len(text), options))
|
||||||
|
}
|
||||||
|
|
||||||
// Custom allocator - Defines the memory allocation functions to be used by CMark
|
// Custom allocator - Defines the memory allocation functions to be used by CMark
|
||||||
// when parsing and allocating a document tree
|
// when parsing and allocating a document tree
|
||||||
Allocator :: struct {
|
Allocator :: struct {
|
||||||
calloc: proc(c.size_t, c.size_t) -> rawptr,
|
calloc: proc "c" (c.size_t, c.size_t) -> rawptr,
|
||||||
realloc: proc(rawptr, c.size_t) -> rawptr,
|
realloc: proc "c" (rawptr, c.size_t) -> rawptr,
|
||||||
free: proc(rawptr),
|
free: proc "c" (rawptr),
|
||||||
}
|
}
|
||||||
|
|
||||||
@(default_calling_convention="c", link_prefix="cmark_")
|
@(default_calling_convention="c", link_prefix="cmark_")
|
||||||
@@ -427,6 +431,13 @@ foreign lib {
|
|||||||
parse_from_libc_file :: proc(file: ^libc.FILE, options: Options) -> (root: ^Node) ---
|
parse_from_libc_file :: proc(file: ^libc.FILE, options: Options) -> (root: ^Node) ---
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parser_feed_from_string :: proc "c" (parser: ^Parser, s: string) {
|
||||||
|
parser_feed(parser, raw_data(s), len(s))
|
||||||
|
}
|
||||||
|
parse_document_from_string :: proc "c" (s: string, options: Options) -> (root: ^Node) {
|
||||||
|
return parse_document(raw_data(s), len(s), options)
|
||||||
|
}
|
||||||
|
|
||||||
// Rendering
|
// Rendering
|
||||||
@(default_calling_convention="c", link_prefix="cmark_")
|
@(default_calling_convention="c", link_prefix="cmark_")
|
||||||
foreign lib {
|
foreign lib {
|
||||||
@@ -453,11 +464,14 @@ foreign lib {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Helpers to free results from `render_*`.
|
// Helpers to free results from `render_*`.
|
||||||
free_rawptr :: proc (ptr: rawptr) {
|
free_rawptr :: proc "c" (ptr: rawptr) {
|
||||||
cmm := get_default_mem_allocator()
|
cmm := get_default_mem_allocator()
|
||||||
cmm.free(ptr)
|
cmm.free(ptr)
|
||||||
}
|
}
|
||||||
free_cstring :: proc (str: cstring) {
|
free_cstring :: proc "c" (str: cstring) {
|
||||||
free_rawptr(rawptr(str))
|
free_rawptr(rawptr(str))
|
||||||
}
|
}
|
||||||
|
free_string :: proc "c" (s: string) {
|
||||||
|
free_rawptr(raw_data(s))
|
||||||
|
}
|
||||||
free :: proc{free_rawptr, free_cstring}
|
free :: proc{free_rawptr, free_cstring}
|
||||||
Reference in New Issue
Block a user