Add language to Item::CodeBlock in markdown

This commit is contained in:
Héctor Ramón Jiménez 2025-02-05 01:33:16 +01:00
parent f8c71a20a9
commit c7711e59ab
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
2 changed files with 31 additions and 17 deletions

View file

@ -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),
)
}
}