use crate::theme::{ActiveTheme, Themeable};
use gpui::{div, prelude::*, rems, App, ElementId, ParentElement, Styled};
use super::super::inline_style::{InlinePalette, RichText};
use super::super::style::TextStyle;
use super::paragraph::{rich_text_run, RunContext};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum HeadingLevel {
H1,
H2,
H3,
H4,
H5,
H6,
}
impl From<pulldown_cmark::HeadingLevel> for HeadingLevel {
fn from(level: pulldown_cmark::HeadingLevel) -> Self {
match level {
pulldown_cmark::HeadingLevel::H1 => HeadingLevel::H1,
pulldown_cmark::HeadingLevel::H2 => HeadingLevel::H2,
pulldown_cmark::HeadingLevel::H3 => HeadingLevel::H3,
pulldown_cmark::HeadingLevel::H4 => HeadingLevel::H4,
pulldown_cmark::HeadingLevel::H5 => HeadingLevel::H5,
pulldown_cmark::HeadingLevel::H6 => HeadingLevel::H6,
}
}
}
pub fn heading(text: impl Into<String>, style: &TextStyle, cx: &App) -> impl IntoElement {
let text: String = text.into();
let theme = cx.theme();
let text_color = style.color.unwrap_or(theme.fg());
div()
.w_full()
.text_size(rems(style.size))
.line_height(rems(style.size * style.line_height))
.font_weight(style.weight)
.text_color(text_color)
.mt(rems(style.margin_top))
.child(text)
}
pub(crate) fn rich_heading(
id: impl Into<ElementId>,
rich_text: &RichText,
style: &TextStyle,
palette: &InlinePalette,
run_cx: RunContext,
cx: &App,
) -> impl IntoElement {
let theme = cx.theme();
let text_color = style.color.unwrap_or(theme.fg());
div()
.w_full()
.text_size(rems(style.size))
.line_height(rems(style.size * style.line_height))
.font_weight(style.weight)
.text_color(text_color)
.mt(rems(style.margin_top))
.child(rich_text_run(id, rich_text, palette, run_cx))
}