Skip to content

Commit 6e4cf42

Browse files
committed
feat(panel): add markdown support for ticket page
1 parent 7d07e30 commit 6e4cf42

6 files changed

Lines changed: 243 additions & 5 deletions

File tree

Cargo.lock

Lines changed: 222 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rustmail_panel/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ serde = { version = "1.0.228", features = ["derive"] }
1818
js-sys = "0.3.77"
1919
wasm-bindgen = "0.2.100"
2020
urlencoding = "2.1.3"
21+
ammonia = "4.1.2"
22+
pulldown-cmark = "0.13.0"
2123
[build-dependencies]
2224
navigator = "0.3.0"

rustmail_panel/src/components/ticket.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::utils::markdown::markdown_to_html_safe;
12
use gloo_net::http::Request;
23
use i18nrs::yew::use_translation;
34
use js_sys::Date;
@@ -300,7 +301,7 @@ pub fn ticket_details(props: &TicketDetailsProps) -> Html {
300301
<span class="text-white text-sm">{ &m.user_name }</span>
301302
<span class="text-xs text-gray-500">{ &m.created_at }</span>
302303
</div>
303-
<p class="text-gray-300 text-sm">{ &m.content }</p>
304+
<p class="text-gray-300 text-sm">{ markdown_to_html_safe(&m.content) }</p>
304305
</div>
305306
}) }
306307
</div>

rustmail_panel/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
mod components;
22
mod pages;
33
mod router;
4+
mod utils;
45

5-
use crate::router::{Route, switch};
6-
use i18nrs::StorageType;
6+
use crate::router::{switch, Route};
77
use i18nrs::yew::I18nProvider;
8+
use i18nrs::StorageType;
89
use std::collections::HashMap;
910
use yew::prelude::*;
1011
use yew_router::prelude::*;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use ammonia::clean;
2+
use pulldown_cmark::{html, Parser};
3+
use yew::{AttrValue, Html};
4+
5+
pub fn markdown_to_html_safe(markdown_input: &str) -> Html {
6+
println!("Markdown input: {}", markdown_input);
7+
let parser = Parser::new(markdown_input);
8+
let mut html_output = String::new();
9+
html::push_html(&mut html_output, parser);
10+
11+
let sanitized = clean(&html_output);
12+
Html::from_html_unchecked(AttrValue::from(sanitized))
13+
}

rustmail_panel/src/utils/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod markdown;

0 commit comments

Comments
 (0)