add: lossy encode webp images

This commit is contained in:
trisua 2025-05-17 11:28:58 -04:00
parent 03480d32db
commit 24162573ee
8 changed files with 145 additions and 437 deletions

View file

@ -1,22 +1,30 @@
use ammonia::Builder;
use comrak::{Options, markdown_to_html};
use markdown::{to_html_with_options, Options, CompileOptions, ParseOptions};
use std::collections::HashSet;
/// Render markdown input into HTML
pub fn render_markdown(input: &str) -> String {
let mut options = Options::default();
let options = Options {
compile: CompileOptions {
allow_any_img_src: false,
allow_dangerous_html: true,
gfm_task_list_item_checkable: false,
gfm_tagfilter: false,
..Default::default()
},
parse: ParseOptions {
gfm_strikethrough_single_tilde: false,
math_text_single_dollar: false,
mdx_expression_parse: None,
mdx_esm_parse: None,
..Default::default()
},
};
options.extension.table = true;
options.extension.superscript = true;
options.extension.strikethrough = true;
options.extension.autolink = true;
options.extension.header_ids = Option::Some(String::new());
// options.extension.tagfilter = true;
options.render.unsafe_ = true;
// options.render.escape = true;
options.parse.smart = false;
let html = markdown_to_html(input, &options);
let html = match to_html_with_options(input, &options) {
Ok(h) => h,
Err(e) => e.to_string(),
};
let mut allowed_attributes = HashSet::new();
allowed_attributes.insert("id");