Fix markdown monospace in headings

This commit is contained in:
2025-08-03 10:08:03 +02:00
parent 0acab0413c
commit 2fb9908329
6 changed files with 65 additions and 42 deletions

View File

@ -1,6 +1,9 @@
use egui::text::{CCursorRange, LayoutJob};
use crate::markdown::Heading;
use crate::{
markdown::Heading,
text_styles::{H1, H1_MONO, H2, H2_MONO, H3, H3_MONO, H4, H4_MONO, H5, H5_MONO, H6, H6_MONO},
};
use super::{Item, Style, parse};
@ -36,7 +39,6 @@ pub fn highlight_markdown(
_cursor: Option<CCursorRange>,
) -> LayoutJob {
let mut job = LayoutJob::default();
let code_style = Style {
code: true,
..Default::default()
@ -74,14 +76,23 @@ fn format_from_style(egui_style: &egui::Style, style: &Style) -> egui::text::Tex
};
let text_style = if let Some(heading) = style.heading {
match heading {
Heading::H1 => TextStyle::Name("H1".into()),
Heading::H2 => TextStyle::Name("H2".into()),
Heading::H3 => TextStyle::Name("H3".into()),
Heading::H4 => TextStyle::Name("H4".into()),
Heading::H5 => TextStyle::Name("H5".into()),
Heading::H6 => TextStyle::Name("H6".into()),
}
let text_style = match (heading, style.code) {
(Heading::H1, false) => H1,
(Heading::H2, false) => H2,
(Heading::H3, false) => H3,
(Heading::H4, false) => H4,
(Heading::H5, false) => H5,
(Heading::H6, false) => H6,
(Heading::H1, true) => H1_MONO,
(Heading::H2, true) => H2_MONO,
(Heading::H3, true) => H3_MONO,
(Heading::H4, true) => H4_MONO,
(Heading::H5, true) => H5_MONO,
(Heading::H6, true) => H6_MONO,
};
TextStyle::Name(text_style.into())
} else if style.code {
TextStyle::Monospace
} else if style.small | style.raised {