iced::widget::markdown

Function parse

pub fn parse(markdown: &str) -> impl Iterator<Item = Item>
Available on crate feature markdown only.
Expand description

Parse the given Markdown content.

ยง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}");
            }
        }
    }
}