add additional settings to control the fonts used for markdown rendering
This commit is contained in:
parent
19569f7900
commit
7e8c1c916f
1 changed files with 16 additions and 3 deletions
|
|
@ -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<Theme> 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()
|
||||
})))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue