-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
comrak_options.rs
92 lines (78 loc) · 2.73 KB
/
comrak_options.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use super::*;
use libc::{c_char, size_t};
use comrak::ComrakOptions;
use paste::paste;
macro_rules! make_bool_option_func {
($opt_type:ident, $name:ident) => {
paste! {
#[no_mangle]
pub extern "C" fn [<comrak_ set_ $opt_type _ option_ $name>](
c_comrak_options: *mut ComrakOptions,
value: bool,
) {
let comrak_options = to_ref_mut!(c_comrak_options);
comrak_options.$opt_type.$name = value;
}
}
};
}
macro_rules! make_c_char_option_func {
($opt_type:ident, $name:ident) => {
paste! {
#[no_mangle]
pub extern "C" fn [<comrak_ set_ $opt_type _ option_ $name>](
c_comrak_options: *mut ComrakOptions,
v: *const c_char,
v_len: size_t,
) {
let comrak_options = to_ref_mut!(c_comrak_options);
if v.is_null() {
comrak_options.$opt_type.$name = None;
} else {
let value = unwrap_or_ret_err_code! { to_str!(v, v_len) };
comrak_options.$opt_type.$name = Some(value.to_string());
}
}
}
};
}
macro_rules! make_size_t_option_func {
($opt_type:ident, $name:ident) => {
paste! {
#[no_mangle]
pub extern "C" fn [<comrak_ set_ $opt_type _ option_ $name>](
c_comrak_options: *mut ComrakOptions,
value: size_t,
) {
let comrak_options = to_ref_mut!(c_comrak_options);
comrak_options.$opt_type.$name = value;
}
}
};
}
#[no_mangle]
pub extern "C" fn comrak_options_new() -> *mut ComrakOptions {
to_ptr_mut(ComrakOptions::default())
}
#[no_mangle]
pub extern "C" fn comrak_options_free(options: *mut ComrakOptions) {
assert!(!options.is_null());
drop(unsafe { Box::from_raw(options) });
}
make_bool_option_func!(extension, strikethrough);
make_bool_option_func!(extension, tagfilter);
make_bool_option_func!(extension, table);
make_bool_option_func!(extension, autolink);
make_bool_option_func!(extension, tasklist);
make_bool_option_func!(extension, superscript);
make_c_char_option_func!(extension, header_ids);
make_bool_option_func!(extension, footnotes);
make_bool_option_func!(extension, description_lists);
make_c_char_option_func!(extension, front_matter_delimiter);
make_bool_option_func!(parse, smart);
make_c_char_option_func!(parse, default_info_string);
make_bool_option_func!(render, hardbreaks);
make_bool_option_func!(render, github_pre_lang);
make_size_t_option_func!(render, width);
make_bool_option_func!(render, unsafe_);
make_bool_option_func!(render, escape);