Fix markdown monospace in headings
This commit is contained in:
@ -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 {
|
||||
|
||||
@ -16,11 +16,6 @@ pub fn parse_tokens<'a>(mut tokens: &[Token<'a>]) -> Vec<Item<'a>> {
|
||||
|
||||
let mut style = Style::default();
|
||||
|
||||
let mono_style = Style {
|
||||
code: true,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
iter::from_fn(move || {
|
||||
if tokens.is_empty() {
|
||||
return None;
|
||||
@ -73,7 +68,10 @@ pub fn parse_tokens<'a>(mut tokens: &[Token<'a>]) -> Vec<Item<'a>> {
|
||||
any_of([TokenKind::Mono, TokenKind::CodeBlock, TokenKind::Newline]),
|
||||
);
|
||||
|
||||
return Some(Item::Text { span, style: mono_style});
|
||||
let mut style = style;
|
||||
style.code = true;
|
||||
|
||||
return Some(Item::Text { span, style });
|
||||
}
|
||||
|
||||
// TODO: different heading strengths
|
||||
|
||||
Reference in New Issue
Block a user