use std::sync::Arc;
use super::{MarkdownRenderContext, render_block, render_inline_block};
use crate::{
app::theme::ThemeMarkdown,
layout::text_style::TextStyle,
markdown::{MarkdownBlock, MarkdownInline, MarkdownListItem},
node::Element,
};
pub(super) type MarkdownListView = Arc<dyn Fn(&MarkdownList<'_>) -> Option<Element> + Send + Sync>;
pub struct MarkdownList<'a> {
pub(super) ordered: bool,
pub(super) start: Option<u64>,
pub(super) items: &'a [MarkdownListItem],
pub(super) style: &'a TextStyle,
pub(super) theme: &'a ThemeMarkdown,
pub(super) render_ctx: &'a MarkdownRenderContext<'a>,
}
impl std::fmt::Debug for MarkdownList<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("MarkdownList")
.field("ordered", &self.ordered)
.field("start", &self.start)
.field("items", &self.items)
.finish_non_exhaustive()
}
}
impl MarkdownList<'_> {
pub fn ordered(&self) -> bool {
self.ordered
}
pub fn start(&self) -> Option<u64> {
self.start
}
pub fn items(&self) -> &[MarkdownListItem] {
self.items
}
pub fn style(&self) -> &TextStyle {
self.style
}
pub fn theme(&self) -> &ThemeMarkdown {
self.theme
}
pub fn inlines(&self, inlines: &[MarkdownInline], style: &TextStyle) -> Element {
render_inline_block(inlines, style.clone(), self.theme, self.render_ctx)
}
pub fn blocks(&self, blocks: &[MarkdownBlock]) -> Vec<Element> {
blocks
.iter()
.map(|block| render_block(block, self.style, self.theme, self.render_ctx))
.collect()
}
}