Skip to content

Commit 1795a3d

Browse files
chrisbobbegnprice
authored andcommitted
content: Consolidate plain-paragraph style in baseContentTextStyle
For non-paragraph content that wants to inherit its font size and line height attributes, it seems at least as natural to inherit them from our plain paragraph style, as from...hmm... TextTheme.bodyMedium, as is happening currently. Doing so should make the content styles more self-contained and decrease the need for nonlocal reasoning when reading the code. These are the elements that inherit both their font-size and line-height attributes: - line breaks (i.e., <br> in a block context; `LineBreakNode`) - list-item markers (e.g., "1." in a numbered list) Instead of font-size 14 and line-height 1.43x, from TextTheme.bodyMedium, those now have font-size 17 and line-height ~1.29x (i.e., 22 / 17). Since the list-item markers change is somewhat conspicuous, I filed #697 ("content: Markers on list items are smaller than list-item text"), which this commit fixes. Code blocks (and our simplified math blocks) set their own font size, but they do inherit their line height. So those now also have a line height of ~1.29x instead of 1.43x. As it happens, web sets a line height of 1.4x for code blocks, which we should probably follow (intentionally). I'll make that adjustment next, but now hopefully this is a helpful structure for our content implementations. Fixes: #697
1 parent 1522e9f commit 1795a3d

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

lib/widgets/content.dart

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ import 'text.dart';
2323
/// The font size for message content in a plain unstyled paragraph.
2424
const double kBaseFontSize = 17;
2525

26-
final baseContentTextStyle = TextStyle(color: const HSLColor.fromAHSL(1, 0, 0, 0.15).toColor());
26+
/// The [TextStyle] we use for plain, unstyled paragraphs.
27+
///
28+
/// Also the base style that all other text content should inherit from.
29+
final plainParagraphContentTextStyle = TextStyle(
30+
color: const HSLColor.fromAHSL(1, 0, 0, 0.15).toColor(),
31+
fontSize: kBaseFontSize,
32+
height: (22 / kBaseFontSize),
33+
);
2734

2835
/// The entire content of a message, aka its body.
2936
///
@@ -39,7 +46,7 @@ class MessageContent extends StatelessWidget {
3946
Widget build(BuildContext context) {
4047
return InheritedMessage(message: message,
4148
child: DefaultTextStyle.merge(
42-
style: baseContentTextStyle,
49+
style: plainParagraphContentTextStyle,
4350
child: BlockContentList(nodes: content.nodes)));
4451
}
4552
}
@@ -138,11 +145,6 @@ class Paragraph extends StatelessWidget {
138145

139146
final ParagraphNode node;
140147

141-
static const textStyle = TextStyle(
142-
fontSize: kBaseFontSize,
143-
height: (22 / kBaseFontSize),
144-
);
145-
146148
@override
147149
Widget build(BuildContext context) {
148150
// Empty paragraph winds up with zero height.
@@ -151,7 +153,7 @@ class Paragraph extends StatelessWidget {
151153

152154
final text = _buildBlockInlineContainer(
153155
node: node,
154-
style: textStyle,
156+
style: DefaultTextStyle.of(context).style,
155157
);
156158

157159
// If the paragraph didn't actually have a `p` element in the HTML,

lib/widgets/profile.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class _LinkWidget extends StatelessWidget {
218218
Widget build(BuildContext context) {
219219
final linkNode = LinkNode(url: url, nodes: [TextNode(text)]);
220220
final paragraph = DefaultTextStyle.merge(
221-
style: baseContentTextStyle,
221+
style: plainParagraphContentTextStyle,
222222
child: Paragraph(node: ParagraphNode(nodes: [linkNode], links: [linkNode])));
223223
return Padding(
224224
padding: const EdgeInsets.symmetric(horizontal: 8),

test/widgets/content_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void main() {
9494

9595
Widget plainContent(String html) {
9696
return DefaultTextStyle.merge(
97-
style: TextStyle(color: const HSLColor.fromAHSL(1, 0, 0, 0.15).toColor()),
97+
style: plainParagraphContentTextStyle,
9898
child: BlockContentList(nodes: parseContent(html).nodes));
9999
}
100100

@@ -540,7 +540,7 @@ void main() {
540540
}, variant: const TargetPlatformVariant({TargetPlatform.android, TargetPlatform.iOS}));
541541

542542
testWidgets('multiple links in paragraph', (tester) async {
543-
final fontSize = Paragraph.textStyle.fontSize!;
543+
final fontSize = plainParagraphContentTextStyle.fontSize!;
544544

545545
await prepare(tester,
546546
'<p><a href="https://a/">foo</a> bar <a href="https://b/">baz</a></p>');
@@ -568,7 +568,7 @@ void main() {
568568
});
569569

570570
testWidgets('link containing other spans', (tester) async {
571-
final fontSize = Paragraph.textStyle.fontSize!;
571+
final fontSize = plainParagraphContentTextStyle.fontSize!;
572572

573573
await prepare(tester,
574574
'<p><a href="https://a/">two <strong><em><code>words</code></em></strong></a></p>');

0 commit comments

Comments
 (0)