|
|
@@ -1,10 +1,14 @@ |
|
|
|
use std::collections::HashMap; |
|
|
|
use std::hash::BuildHasher; |
|
|
|
|
|
|
|
use base64::{decode, encode}; |
|
|
|
use pulldown_cmark as cmark; |
|
|
|
use tera::{to_value, Result as TeraResult, Value}; |
|
|
|
|
|
|
|
pub fn markdown(value: &Value, args: &HashMap<String, Value>) -> TeraResult<Value> { |
|
|
|
pub fn markdown<S: BuildHasher>( |
|
|
|
value: &Value, |
|
|
|
args: &HashMap<String, Value, S>, |
|
|
|
) -> TeraResult<Value> { |
|
|
|
let s = try_get_value!("markdown", "value", String, value); |
|
|
|
let inline = match args.get("inline") { |
|
|
|
Some(val) => try_get_value!("markdown", "inline", bool, val), |
|
|
@@ -30,12 +34,18 @@ pub fn markdown(value: &Value, args: &HashMap<String, Value>) -> TeraResult<Valu |
|
|
|
Ok(to_value(&html).unwrap()) |
|
|
|
} |
|
|
|
|
|
|
|
pub fn base64_encode(value: &Value, _: &HashMap<String, Value>) -> TeraResult<Value> { |
|
|
|
pub fn base64_encode<S: BuildHasher>( |
|
|
|
value: &Value, |
|
|
|
_: &HashMap<String, Value, S>, |
|
|
|
) -> TeraResult<Value> { |
|
|
|
let s = try_get_value!("base64_encode", "value", String, value); |
|
|
|
Ok(to_value(&encode(s.as_bytes())).unwrap()) |
|
|
|
} |
|
|
|
|
|
|
|
pub fn base64_decode(value: &Value, _: &HashMap<String, Value>) -> TeraResult<Value> { |
|
|
|
pub fn base64_decode<S: BuildHasher>( |
|
|
|
value: &Value, |
|
|
|
_: &HashMap<String, Value, S>, |
|
|
|
) -> TeraResult<Value> { |
|
|
|
let s = try_get_value!("base64_decode", "value", String, value); |
|
|
|
Ok(to_value(&String::from_utf8(decode(s.as_bytes()).unwrap()).unwrap()).unwrap()) |
|
|
|
} |
|
|
|