diff options
author | 2025-02-05 01:33:16 +0100 | |
---|---|---|
committer | 2025-02-05 01:33:16 +0100 | |
commit | c7711e59ab74f9cd5a31229b8fc4191ca1322917 (patch) | |
tree | 5bd6eb5f50206ef16f5a8d1f5d4f2a9a89023c2d /examples | |
parent | f8c71a20a99568b2ddd0e07ac021d37ce2933856 (diff) | |
download | iced-c7711e59ab74f9cd5a31229b8fc4191ca1322917.tar.gz iced-c7711e59ab74f9cd5a31229b8fc4191ca1322917.tar.bz2 iced-c7711e59ab74f9cd5a31229b8fc4191ca1322917.zip |
Add `language` to `Item::CodeBlock` in `markdown`
Diffstat (limited to 'examples')
-rw-r--r-- | examples/markdown/src/main.rs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/examples/markdown/src/main.rs b/examples/markdown/src/main.rs index 20957bcd..512d4b44 100644 --- a/examples/markdown/src/main.rs +++ b/examples/markdown/src/main.rs @@ -6,8 +6,8 @@ use iced::highlighter; use iced::task; use iced::time::{self, milliseconds, Instant}; use iced::widget::{ - self, button, center_x, horizontal_space, hover, image, markdown, pop, - right, row, scrollable, text_editor, toggler, + self, button, center_x, container, horizontal_space, hover, image, + markdown, pop, right, row, scrollable, text_editor, toggler, }; use iced::window; use iced::{Animation, Element, Fill, Font, Subscription, Task, Theme}; @@ -294,20 +294,22 @@ impl<'a> markdown::Viewer<'a, Message> for CustomViewer<'a> { fn code_block( &self, settings: markdown::Settings, + _language: Option<&'a str>, code: &'a str, lines: &'a [markdown::Text], ) -> Element<'a, Message> { let code_block = - markdown::code_block(settings, code, lines, Message::LinkClicked); + markdown::code_block(settings, lines, Message::LinkClicked); + + let copy = button(icon::copy().size(12)) + .padding(2) + .on_press_with(|| Message::Copy(code.to_owned())) + .style(button::text); hover( code_block, - right( - button(icon::copy().size(12)) - .padding(settings.spacing / 2) - .on_press_with(|| Message::Copy(code.to_owned())) - .style(button::text), - ), + right(container(copy).style(container::dark)) + .padding(settings.spacing / 2), ) } } |