Skip to content

Commit ce28fbb

Browse files
committed
content: Make **bold** bolder even in spoiler headers and h1/h2/etc.
Fixes: zulip#705
1 parent 26d6806 commit ce28fbb

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

lib/widgets/content.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,12 @@ class InlineContent extends StatelessWidget {
723723
required this.nodes,
724724
}) {
725725
assert(style.fontSize != null);
726+
assert(
727+
style.debugLabel!.contains('weightVariableTextStyle')
728+
// ([ContentTheme.textStylePlainParagraph] applies [weightVariableTextStyle])
729+
|| style.debugLabel!.contains('ContentTheme.textStylePlainParagraph')
730+
|| style.debugLabel!.contains('bolderWghtTextStyle')
731+
);
726732
_builder = _InlineContentBuilder(this);
727733
}
728734

@@ -733,6 +739,7 @@ class InlineContent extends StatelessWidget {
733739
///
734740
/// Must set [TextStyle.fontSize]. Some descendant spans will consume it,
735741
/// e.g., to make their content slightly smaller than surrounding text.
742+
/// Similarly must set a font weight using [weightVariableTextStyle].
736743
final TextStyle style;
737744

738745
final List<InlineContentNode> nodes;
@@ -831,8 +838,9 @@ class _InlineContentBuilder {
831838
}
832839
}
833840

834-
InlineSpan _buildStrong(StrongNode node) => _buildNodes(node.nodes,
835-
style: weightVariableTextStyle(_context!, wght: 600));
841+
InlineSpan _buildStrong(StrongNode node) =>
842+
_buildNodes(style: bolderWghtTextStyle(widget.style, by: 200),
843+
node.nodes);
836844

837845
InlineSpan _buildDeleted(DeletedNode node) => _buildNodes(node.nodes,
838846
style: const TextStyle(decoration: TextDecoration.lineThrough));

test/widgets/content_test.dart

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,54 @@ void main() {
519519
content: plainContent('<p><strong>bold</strong></p>'),
520520
styleFinder: findWordBold,
521521
);
522+
523+
for (final level in HeadingLevel.values) {
524+
final name = level.name;
525+
assert(RegExp(r'^h[1-6]$').hasMatch(name));
526+
testFontWeight('in $name',
527+
expectedWght: 800,
528+
// # **bold**, ## **bold**, ### **bold**, etc.
529+
content: plainContent('<$name><strong>bold</strong></$name>'),
530+
styleFinder: findWordBold,
531+
);
532+
}
533+
534+
testFontWeight('in different kind of span in h1',
535+
expectedWght: 800,
536+
// # ~~**bold**~~
537+
content: plainContent('<h1><del><strong>bold</strong></del></h1>'),
538+
styleFinder: findWordBold,
539+
);
540+
541+
testFontWeight('in spoiler header',
542+
expectedWght: 900,
543+
// ```spoiler regular **bold**
544+
// content
545+
// ```
546+
content: plainContent(
547+
'<div class="spoiler-block"><div class="spoiler-header">\n'
548+
'<p>regular <strong>bold</strong></p>\n'
549+
'</div><div class="spoiler-content" aria-hidden="true">\n'
550+
'<p>content</p>\n'
551+
'</div></div>'
552+
),
553+
styleFinder: findWordBold,
554+
);
555+
556+
testFontWeight('in different kind of span in spoiler header',
557+
expectedWght: 900,
558+
// ```spoiler *italic **bold***
559+
// content
560+
// ```
561+
content: plainContent(
562+
'<div class="spoiler-block"><div class="spoiler-header">\n'
563+
'<p><em>italic <strong>bold</strong></em></p>\n'
564+
'</div><div class="spoiler-content" aria-hidden="true">\n'
565+
'<p>content</p>\n'
566+
'</div></div>'
567+
),
568+
styleFinder: findWordBold,
569+
);
522570
});
523571

524572
testContentSmoke(ContentExample.emphasis);

0 commit comments

Comments
 (0)