Support rendering markdown content
This commit is contained in:
@@ -4,6 +4,7 @@ use gtk::prelude::*;
|
||||
use relm4_components::web_image::WebImage;
|
||||
|
||||
use crate::util::get_web_image_url;
|
||||
use crate::util::markdown_to_pango_markup;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CommentRow {
|
||||
@@ -56,8 +57,9 @@ impl FactoryComponent for CommentRow {
|
||||
},
|
||||
|
||||
gtk::Label {
|
||||
set_label: &self.comment.comment.content,
|
||||
set_markup: &markdown_to_pango_markup(self.comment.comment.content.clone()),
|
||||
set_halign: gtk::Align::Start,
|
||||
set_use_markup: true,
|
||||
},
|
||||
|
||||
gtk::Label {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::util::markdown_to_pango_markup;
|
||||
use lemmy_api_common::{community::GetCommunityResponse, lemmy_db_views::structs::PostView};
|
||||
use relm4::{prelude::*, factory::FactoryVecDeque};
|
||||
use gtk::prelude::*;
|
||||
@@ -47,7 +48,8 @@ impl SimpleComponent for CommunityPage {
|
||||
},
|
||||
gtk::Label {
|
||||
#[watch]
|
||||
set_text: &model.info.clone().community_view.community.description.unwrap_or("".to_string()),
|
||||
set_markup: &markdown_to_pango_markup(model.info.clone().community_view.community.description.unwrap_or("".to_string())),
|
||||
set_use_markup: true,
|
||||
},
|
||||
gtk::Label {
|
||||
#[watch]
|
||||
|
||||
@@ -3,7 +3,7 @@ use relm4::{prelude::*, factory::FactoryVecDeque};
|
||||
use gtk::prelude::*;
|
||||
use relm4_components::web_image::WebImage;
|
||||
|
||||
use crate::{api, util::{get_web_image_msg, get_web_image_url}};
|
||||
use crate::{api, util::{get_web_image_msg, get_web_image_url, markdown_to_pango_markup}};
|
||||
|
||||
use super::comment_row::CommentRow;
|
||||
|
||||
@@ -50,8 +50,9 @@ impl SimpleComponent for PostPage {
|
||||
},
|
||||
gtk::Label {
|
||||
#[watch]
|
||||
set_text: &model.info.clone().post_view.post.body.unwrap_or("".to_string()),
|
||||
set_markup: &markdown_to_pango_markup(model.info.post_view.post.body.clone().unwrap_or("".to_string())),
|
||||
set_margin_top: 10,
|
||||
set_use_markup: true,
|
||||
},
|
||||
|
||||
gtk::Box {
|
||||
|
||||
@@ -4,6 +4,7 @@ use gtk::prelude::*;
|
||||
use relm4_components::web_image::WebImage;
|
||||
|
||||
use crate::util::get_web_image_msg;
|
||||
use crate::util::markdown_to_pango_markup;
|
||||
|
||||
use super::post_row::PostRow;
|
||||
|
||||
@@ -44,7 +45,8 @@ impl SimpleComponent for ProfilePage {
|
||||
},
|
||||
gtk::Label {
|
||||
#[watch]
|
||||
set_text: &model.info.person_view.person.bio.clone().unwrap_or("".to_string()),
|
||||
set_markup: &markdown_to_pango_markup(model.info.person_view.person.bio.clone().unwrap_or("".to_string())),
|
||||
set_use_markup: true,
|
||||
},
|
||||
|
||||
gtk::Box {
|
||||
|
||||
@@ -12,3 +12,7 @@ pub fn get_web_image_url(url: Option<DbUrl>) -> String {
|
||||
url.to_string()
|
||||
} else { String::from("") }
|
||||
}
|
||||
|
||||
pub fn markdown_to_pango_markup(text: String) -> String {
|
||||
return html2pango::markup_html(&markdown::to_html(&text)).unwrap_or(text)
|
||||
}
|
||||
Reference in New Issue
Block a user