FEATURE: when rich-editor is enabled use Jetbrains Mono as code font (#32122)

This change forces consistency around code font in Discourse once the
new
rich-editor is enabled

- This means all code blocks in Discourse will render with this font
- Additionally the markdown mode composer will render with this font

Additionally we make 3 small adjustments:

1. We disable ligatures which conflict with typographer
2. We add support for custom ligature settings
3. We adjust down font size, cause 14px ends up matching visually with a
16px non monospace font, this change is already in place previously on
posts

Example:


![image](https://github.com/user-attachments/assets/eca0b544-f3a4-4172-b2af-b39a3c0208e7)
This commit is contained in:
Sam
2025-04-02 16:36:52 +11:00
committed by GitHub
parent e4244cca35
commit c0cf898c10
4 changed files with 32 additions and 5 deletions

View File

@ -64,9 +64,31 @@ module Stylesheet
CSS
if SiteSetting.rich_editor
contents << <<~CSS
#{font_css(jetbrains_mono)}
#{render_font_special_properties(jetbrains_mono, "body")}
:root {
--d-font-family--monospace: #{jetbrains_mono[:stack]};
}
CSS
else
contents << <<~CSS
:root {
--d-font-family--monospace: ui-monospace, "Cascadia Mono", "Segoe UI Mono", "Liberation Mono", menlo, monaco, consolas, monospace;
}
CSS
end
contents
end
def jetbrains_mono
@@jetbrains_mono ||= DiscourseFonts.fonts.find { |f| f[:key] == "jet_brains_mono" }
end
def wizard_fonts
contents = +""
@ -262,6 +284,12 @@ module Stylesheet
else
contents << "#{" " * indent}font-feature-settings: normal;\n"
end
# avoiding adding normal to the CSS cause it is not needed in this case
if font[:font_variant_ligatures].present?
contents << "#{" " * indent}font-variant-ligatures: #{font[:font_variant_ligatures]};\n"
end
contents
end
end