iced::widget

Function markdown

pub fn markdown<'a, 'b, Theme, Renderer>(
    items: impl IntoIterator<Item = &'b Item>,
    settings: Settings,
    style: Style,
) -> Element<'a, Url, Theme, Renderer>
where Theme: Catalog + 'a, Renderer: Renderer<Font = Font> + 'a,
Expand description

Display a bunch of Markdown items.

You can obtain the items with parse.

ยงExample

use iced::widget::markdown;
use iced::Theme;

struct State {
   markdown: Vec<markdown::Item>,
}

enum Message {
    LinkClicked(markdown::Url),
}

impl State {
    pub fn new() -> Self {
        Self {
            markdown: markdown::parse("This is some **Markdown**!").collect(),
        }
    }

    fn view(&self) -> Element<'_, Message> {
        markdown::view(
            &self.markdown,
            markdown::Settings::default(),
            markdown::Style::from_palette(Theme::TokyoNightStorm.palette()),
        )
        .map(Message::LinkClicked)
        .into()
    }

    fn update(state: &mut State, message: Message) {
        match message {
            Message::LinkClicked(url) => {
                println!("The following url was clicked: {url}");
            }
        }
    }
}