Skip to content

Commit 8415411

Browse files
committed
content: Fix **bold code** rendering with regular weight
Our experience with variable-weight fonts is that, whenever we use such a font, we need to specify a "wght" value, even if we want the text to appear in the boring, regular weight. If we don't specify a "wght", the text will appear in an extremely light weight. We use a variable-weight font (Source Code Pro) for rendering inline code spans, so that's why we were using weightVariableTextStyle here. As an unfortunate result, when a code span appears inside a bold ("strong") span, the outer span's bold-weight style has been getting clobbered, and the code span appears in regular weight. Fortunately, removing the `weightVariableTextStyle` from the inline code style doesn't actually cause any inline spans to appear at minimum weight. This is a relief, and it follows from the presence of a `weightVariableTextStyle` applied at the paragraph-content level. We use `weightVariableTextStyle` there because the paragraph font, Source Sans 3, is also a variable-weight font. Moreover, Source Code Pro and Source Sans 3 seem closely related (and were designed by the same person), so it's likely that their "wght" axes are identical. Fixes: #498
1 parent 53ed506 commit 8415411

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/widgets/content.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,18 @@ class _InlineContentBuilder {
600600
final _kInlineMathStyle = _kInlineCodeStyle.merge(TextStyle(
601601
backgroundColor: const HSLColor.fromAHSL(1, 240, 0.4, 0.93).toColor()));
602602

603+
// Even though [kMonospaceTextStyle] is a variable-weight font,
604+
// it's acceptable to skip [weightVariableTextStyle] here,
605+
// assuming the text gets the effect of [weightVariableTextStyle]
606+
// through inheritance, e.g., from a [DefaultTextStyle].
603607
final _kInlineCodeStyle = kMonospaceTextStyle
604608
.merge(const TextStyle(
605609
backgroundColor: Color(0xffeeeeee),
610+
fontSize: 0.825 * kBaseFontSize));
611+
612+
final _kCodeBlockStyle = kMonospaceTextStyle
613+
.merge(const TextStyle(
614+
backgroundColor: Color.fromRGBO(255, 255, 255, 1),
606615
fontSize: 0.825 * kBaseFontSize))
607616
.merge(
608617
// TODO(a11y) pass a BuildContext, to handle platform request for bold text.
@@ -612,14 +621,6 @@ final _kInlineCodeStyle = kMonospaceTextStyle
612621
// frequently. Then consumers can just look it up on the InheritedWidget.
613622
weightVariableTextStyle(null));
614623

615-
final _kCodeBlockStyle = kMonospaceTextStyle
616-
.merge(const TextStyle(
617-
backgroundColor: Color.fromRGBO(255, 255, 255, 1),
618-
fontSize: 0.825 * kBaseFontSize))
619-
.merge(
620-
// TODO(a11y) pass a BuildContext; see comment in _kInlineCodeStyle above.
621-
weightVariableTextStyle(null));
622-
623624
// const _kInlineCodeLeftBracket = '⸤';
624625
// const _kInlineCodeRightBracket = '⸣';
625626
// Some alternatives:

0 commit comments

Comments
 (0)