Make RichText generic over data structure

... and decouple `markdown::parse` from theming
This commit is contained in:
Héctor Ramón Jiménez 2024-08-22 02:24:06 +02:00
parent 55764b923e
commit 4c883f12b4
No known key found for this signature in database
GPG key ID: 4C07CEC81AFA161F
7 changed files with 223 additions and 94 deletions

View file

@ -29,8 +29,7 @@ impl Markdown {
(
Self {
content: text_editor::Content::with_text(INITIAL_CONTENT),
items: markdown::parse(INITIAL_CONTENT, theme.palette())
.collect(),
items: markdown::parse(INITIAL_CONTENT).collect(),
theme,
},
widget::focus_next(),
@ -45,11 +44,8 @@ impl Markdown {
self.content.perform(action);
if is_edit {
self.items = markdown::parse(
&self.content.text(),
self.theme.palette(),
)
.collect();
self.items =
markdown::parse(&self.content.text()).collect();
}
}
Message::LinkClicked(link) => {
@ -67,8 +63,12 @@ impl Markdown {
.font(Font::MONOSPACE)
.highlight("markdown", highlighter::Theme::Base16Ocean);
let preview = markdown(&self.items, markdown::Settings::default())
.map(Message::LinkClicked);
let preview = markdown(
&self.items,
markdown::Settings::default(),
markdown::Style::from_palette(self.theme.palette()),
)
.map(Message::LinkClicked);
row![editor, scrollable(preview).spacing(10).height(Fill)]
.spacing(10)