From c7711e59ab74f9cd5a31229b8fc4191ca1322917 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 5 Feb 2025 01:33:16 +0100 Subject: Add `language` to `Item::CodeBlock` in `markdown` --- examples/markdown/src/main.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'examples') 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), ) } } -- cgit