Skip to content

Commit ddb6f14

Browse files
committed
add additional settings to control the fonts used for markdown rendering
1 parent d4f8e19 commit ddb6f14

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

widget/src/markdown.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,14 @@ impl Span {
312312
let span = span(text.clone()).strikethrough(*strikethrough);
313313

314314
let span = if *code {
315-
span.font(Font::MONOSPACE)
315+
span.font(style.inline_code_font)
316316
.color(style.inline_code_color)
317317
.background(style.inline_code_highlight.background)
318318
.border(style.inline_code_highlight.border)
319319
.padding(style.inline_code_padding)
320320
} else if *strong || *emphasis {
321321
span.font(Font {
322+
family: style.text_font_family,
322323
weight: if *strong {
323324
font::Weight::Bold
324325
} else {
@@ -332,7 +333,10 @@ impl Span {
332333
..Font::default()
333334
})
334335
} else {
335-
span
336+
span.font(Font {
337+
family: style.text_font_family,
338+
..Font::default()
339+
})
336340
};
337341

338342
if let Some(link) = link.as_ref() {
@@ -1056,12 +1060,18 @@ impl From<Theme> for Settings {
10561060
/// The text styling of some Markdown rendering in [`view`].
10571061
#[derive(Debug, Clone, Copy, PartialEq)]
10581062
pub struct Style {
1063+
/// The [`font::Family`] to be applied to non-code text.
1064+
pub text_font_family: font::Family,
10591065
/// The [`Highlight`] to be applied to the background of inline code.
10601066
pub inline_code_highlight: Highlight,
10611067
/// The [`Padding`] to be applied to the background of inline code.
10621068
pub inline_code_padding: Padding,
10631069
/// The [`Color`] to be applied to inline code.
10641070
pub inline_code_color: Color,
1071+
/// The [`Font`] to be applied to inline code.
1072+
pub inline_code_font: Font,
1073+
/// The [`Font`] to be applied to code blocks.
1074+
pub code_block_font: Font,
10651075
/// The [`Color`] to be applied to links.
10661076
pub link_color: Color,
10671077
}
@@ -1070,12 +1080,15 @@ impl Style {
10701080
/// Creates a new [`Style`] from the given [`theme::Palette`].
10711081
pub fn from_palette(palette: theme::Palette) -> Self {
10721082
Self {
1083+
text_font_family: font::Family::default(),
10731084
inline_code_padding: padding::left(1).right(1),
10741085
inline_code_highlight: Highlight {
10751086
background: color!(0x111).into(),
10761087
border: border::rounded(2),
10771088
},
10781089
inline_code_color: Color::WHITE,
1090+
inline_code_font: Font::MONOSPACE,
1091+
code_block_font: Font::MONOSPACE,
10791092
link_color: palette.primary,
10801093
}
10811094
}
@@ -1357,7 +1370,7 @@ where
13571370
container(column(lines.iter().map(|line| {
13581371
rich_text(line.spans(settings.style))
13591372
.on_link_click(on_link_click.clone())
1360-
.font(Font::MONOSPACE)
1373+
.font(settings.style.code_block_font)
13611374
.size(settings.code_size)
13621375
.into()
13631376
})))

0 commit comments

Comments
 (0)