Skip to content

Commit

Permalink
Decouple markdown widget from built-in Theme
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Aug 21, 2024
1 parent 9b99b93 commit 55764b9
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions widget/src/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use crate::core::border;
use crate::core::font::{self, Font};
use crate::core::padding;
use crate::core::theme::{self, Theme};
use crate::core::{self, color, Color, Element, Length, Pixels};
use crate::core::theme;
use crate::core::{self, color, Color, Element, Length, Pixels, Theme};
use crate::{column, container, rich_text, row, scrollable, span, text};

pub use pulldown_cmark::HeadingLevel;
Expand Down Expand Up @@ -349,11 +349,12 @@ impl Default for Settings {
/// Display a bunch of Markdown items.
///
/// You can obtain the items with [`parse`].
pub fn view<'a, Renderer>(
pub fn view<'a, Theme, Renderer>(
items: impl IntoIterator<Item = &'a Item>,
settings: Settings,
) -> Element<'a, Url, Theme, Renderer>
where
Theme: Catalog + 'a,
Renderer: core::text::Renderer<Font = Font> + 'a,
{
let Settings {
Expand Down Expand Up @@ -426,9 +427,23 @@ where
)
.width(Length::Fill)
.padding(spacing.0 / 2.0)
.style(container::dark)
.class(Theme::code_block())
.into(),
});

Element::new(column(blocks).width(Length::Fill).spacing(text_size))
}

/// The theme catalog of Markdown items.
pub trait Catalog:
container::Catalog + scrollable::Catalog + text::Catalog
{
/// The styling class of a Markdown code block.
fn code_block<'a>() -> <Self as container::Catalog>::Class<'a>;
}

impl Catalog for Theme {
fn code_block<'a>() -> <Self as container::Catalog>::Class<'a> {
Box::new(container::dark)
}
}

0 comments on commit 55764b9

Please sign in to comment.