From 7e8c1c916f6cd30de619d738a8d463f5f82524c3 Mon Sep 17 00:00:00 2001 From: James Brumond Date: Sun, 22 Jun 2025 13:42:26 -0700 Subject: [PATCH 1/2] add additional settings to control the fonts used for markdown rendering --- widget/src/markdown.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/widget/src/markdown.rs b/widget/src/markdown.rs index 3d6cd056..535733c5 100644 --- a/widget/src/markdown.rs +++ b/widget/src/markdown.rs @@ -313,13 +313,14 @@ impl Span { let span = span(text.clone()).strikethrough(*strikethrough); let span = if *code { - span.font(Font::MONOSPACE) + span.font(style.inline_code_font) .color(style.inline_code_color) .background(style.inline_code_highlight.background) .border(style.inline_code_highlight.border) .padding(style.inline_code_padding) } else if *strong || *emphasis { span.font(Font { + family: style.text_font_family, weight: if *strong { font::Weight::Bold } else { @@ -333,7 +334,10 @@ impl Span { ..Font::default() }) } else { - span + span.font(Font { + family: style.text_font_family, + ..Font::default() + }) }; if let Some(link) = link.as_ref() { @@ -1046,12 +1050,18 @@ impl From for Settings { /// The text styling of some Markdown rendering in [`view`]. #[derive(Debug, Clone, Copy, PartialEq)] pub struct Style { + /// The [`font::Family`] to be applied to non-code text. + pub text_font_family: font::Family, /// The [`Highlight`] to be applied to the background of inline code. pub inline_code_highlight: Highlight, /// The [`Padding`] to be applied to the background of inline code. pub inline_code_padding: Padding, /// The [`Color`] to be applied to inline code. pub inline_code_color: Color, + /// The [`Font`] to be applied to inline code. + pub inline_code_font: Font, + /// The [`Font`] to be applied to code blocks. + pub code_block_font: Font, /// The [`Color`] to be applied to links. pub link_color: Color, } @@ -1060,12 +1070,15 @@ impl Style { /// Creates a new [`Style`] from the given [`theme::Palette`]. pub fn from_palette(palette: theme::Palette) -> Self { Self { + text_font_family: font::Family::default(), inline_code_padding: padding::left(1).right(1), inline_code_highlight: Highlight { background: color!(0x111111).into(), border: border::rounded(4), }, inline_code_color: Color::WHITE, + inline_code_font: Font::MONOSPACE, + code_block_font: Font::MONOSPACE, link_color: palette.primary, } } @@ -1351,7 +1364,7 @@ where container(column(lines.iter().map(|line| { rich_text(line.spans(settings.style)) .on_link_click(on_link_click.clone()) - .font(Font::MONOSPACE) + .font(settings.style.code_block_font) .size(settings.code_size) .into() }))) From c80b62790f6fbcdb255d8ce6efd72a1b452a7723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sat, 29 Nov 2025 06:34:48 +0100 Subject: [PATCH 2/2] Replace `text_font_family` with `font` in `markdown` --- widget/src/markdown.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/widget/src/markdown.rs b/widget/src/markdown.rs index 535733c5..7694bb5a 100644 --- a/widget/src/markdown.rs +++ b/widget/src/markdown.rs @@ -320,7 +320,6 @@ impl Span { .padding(style.inline_code_padding) } else if *strong || *emphasis { span.font(Font { - family: style.text_font_family, weight: if *strong { font::Weight::Bold } else { @@ -331,13 +330,10 @@ impl Span { } else { font::Style::Normal }, - ..Font::default() + ..style.font }) } else { - span.font(Font { - family: style.text_font_family, - ..Font::default() - }) + span.font(style.font) }; if let Some(link) = link.as_ref() { @@ -1050,8 +1046,8 @@ impl From for Settings { /// The text styling of some Markdown rendering in [`view`]. #[derive(Debug, Clone, Copy, PartialEq)] pub struct Style { - /// The [`font::Family`] to be applied to non-code text. - pub text_font_family: font::Family, + /// The [`Font`] to be applied to basic text. + pub font: Font, /// The [`Highlight`] to be applied to the background of inline code. pub inline_code_highlight: Highlight, /// The [`Padding`] to be applied to the background of inline code. @@ -1070,7 +1066,7 @@ impl Style { /// Creates a new [`Style`] from the given [`theme::Palette`]. pub fn from_palette(palette: theme::Palette) -> Self { Self { - text_font_family: font::Family::default(), + font: Font::default(), inline_code_padding: padding::left(1).right(1), inline_code_highlight: Highlight { background: color!(0x111111).into(),