add: render_markdown_dirty
This commit is contained in:
parent
9aed5de097
commit
8786cb4781
3 changed files with 25 additions and 15 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -3353,7 +3353,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tetratto-shared"
|
||||
version = "12.0.4"
|
||||
version = "12.0.5"
|
||||
dependencies = [
|
||||
"ammonia",
|
||||
"chrono",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "tetratto-shared"
|
||||
description = "Shared stuff for Tetratto"
|
||||
version = "12.0.4"
|
||||
version = "12.0.5"
|
||||
edition = "2024"
|
||||
authors.workspace = true
|
||||
repository.workspace = true
|
||||
|
|
|
@ -2,8 +2,7 @@ use ammonia::Builder;
|
|||
use pulldown_cmark::{Parser, Options, html::push_html};
|
||||
use std::collections::HashSet;
|
||||
|
||||
/// Render markdown input into HTML
|
||||
pub fn render_markdown(input: &str, proxy_images: bool) -> String {
|
||||
pub fn render_markdown_dirty(input: &str) -> String {
|
||||
let input = &autolinks(&parse_alignment(input));
|
||||
|
||||
let mut options = Options::empty();
|
||||
|
@ -20,6 +19,27 @@ pub fn render_markdown(input: &str, proxy_images: bool) -> String {
|
|||
let mut html = String::new();
|
||||
push_html(&mut html, parser);
|
||||
|
||||
html
|
||||
}
|
||||
|
||||
pub fn clean_html(html: String, allowed_attributes: HashSet<&str>) -> String {
|
||||
Builder::default()
|
||||
.generic_attributes(allowed_attributes)
|
||||
.add_tags(&[
|
||||
"video", "source", "img", "b", "span", "p", "i", "strong", "em", "a", "align",
|
||||
])
|
||||
.rm_tags(&["script", "style", "link", "canvas"])
|
||||
.add_tag_attributes("a", &["href", "target"])
|
||||
.add_url_schemes(&["atto"])
|
||||
.clean(&html)
|
||||
.to_string()
|
||||
.replace("<video loading=", "<video controls loading=")
|
||||
}
|
||||
|
||||
/// Render markdown input into HTML
|
||||
pub fn render_markdown(input: &str, proxy_images: bool) -> String {
|
||||
let html = render_markdown_dirty(input);
|
||||
|
||||
let mut allowed_attributes = HashSet::new();
|
||||
allowed_attributes.insert("id");
|
||||
allowed_attributes.insert("class");
|
||||
|
@ -30,17 +50,7 @@ pub fn render_markdown(input: &str, proxy_images: bool) -> String {
|
|||
allowed_attributes.insert("align");
|
||||
allowed_attributes.insert("src");
|
||||
|
||||
let output = Builder::default()
|
||||
.generic_attributes(allowed_attributes)
|
||||
.add_tags(&[
|
||||
"video", "source", "img", "b", "span", "p", "i", "strong", "em", "a", "align",
|
||||
])
|
||||
.rm_tags(&["script", "style", "link", "canvas"])
|
||||
.add_tag_attributes("a", &["href", "target"])
|
||||
.add_url_schemes(&["atto"])
|
||||
.clean(&html)
|
||||
.to_string()
|
||||
.replace("<video loading=", "<video controls loading=");
|
||||
let output = clean_html(html, allowed_attributes);
|
||||
|
||||
if proxy_images {
|
||||
output.replace(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue