This commit is contained in:
byte[] 2021-09-29 21:25:53 -04:00
parent fd17684882
commit ba0ffa0fc7
3 changed files with 11 additions and 8 deletions

3
.gitignore vendored
View file

@ -39,6 +39,9 @@ npm-debug.log
# Intellij IDEA
.idea
# VS Code
.vscode
# ElixirLS
.elixir_ls

View file

@ -15,12 +15,12 @@ rustler::init! {
// Markdown NIF wrappers.
#[rustler::nif(schedule = "DirtyCpu")]
fn markdown_to_html<'a>(input: String, reps: Term<'a>) -> String {
fn markdown_to_html(input: String, reps: Term) -> String {
markdown::to_html(input, reps)
}
#[rustler::nif(schedule = "DirtyCpu")]
fn markdown_to_html_unsafe<'a>(input: String, reps: Term<'a>) -> String {
fn markdown_to_html_unsafe(input: String, reps: Term) -> String {
markdown::to_html_unsafe(input, reps)
}

View file

@ -18,14 +18,14 @@ fn common_options() -> ComrakOptions {
options.extension.camoifier = Some(|s| camo::image_url(s).unwrap_or_else(|| String::from("")));
if let Some(domains) = env::var("SITE_DOMAINS").ok() {
options.extension.philomena_domains = Some(domains.split(",").map(|s| s.to_string()).collect::<Vec<String>>());
};
if let Ok(domains) = env::var("SITE_DOMAINS") {
options.extension.philomena_domains = Some(domains.split(',').map(|s| s.to_string()).collect::<Vec<String>>());
}
options
}
fn map_to_hashmap<'a>(map: Term<'a>) -> Option<HashMap<String, String>> {
fn map_to_hashmap(map: Term) -> Option<HashMap<String, String>> {
Some(MapIterator::new(map)?.map(|(key, value)| {
let key: String = key.decode().unwrap_or_else(|_| String::from(""));
let value: String = value.decode().unwrap_or_else(|_| String::from(""));
@ -34,7 +34,7 @@ fn map_to_hashmap<'a>(map: Term<'a>) -> Option<HashMap<String, String>> {
}).collect())
}
pub fn to_html<'a>(input: String, reps: Term<'a>) -> String {
pub fn to_html(input: String, reps: Term) -> String {
let mut options = common_options();
options.render.escape = true;
@ -43,7 +43,7 @@ pub fn to_html<'a>(input: String, reps: Term<'a>) -> String {
comrak::markdown_to_html(&input, &options)
}
pub fn to_html_unsafe<'a>(input: String, reps: Term<'a>) -> String {
pub fn to_html_unsafe(input: String, reps: Term) -> String {
let mut options = common_options();
options.render.unsafe_ = true;