Skip to content

Commit

Permalink
content: Make **bold** bolder even in spoiler headers and h1/h2/etc.
Browse files Browse the repository at this point in the history
Fixes: zulip#705
  • Loading branch information
chrisbobbe committed May 31, 2024
1 parent 54fc1a0 commit 61754f7
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/widgets/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,12 @@ class InlineContent extends StatelessWidget {
required this.nodes,
}) {
assert(style.fontSize != null);
assert(
style.debugLabel!.contains('weightVariableTextStyle')
// ([ContentTheme.textStylePlainParagraph] applies [weightVariableTextStyle])
|| style.debugLabel!.contains('ContentTheme.textStylePlainParagraph')
|| style.debugLabel!.contains('bolderWghtTextStyle')
);
_builder = _InlineContentBuilder(this);
}

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

final List<InlineContentNode> nodes;
Expand Down Expand Up @@ -831,8 +838,9 @@ class _InlineContentBuilder {
}
}

InlineSpan _buildStrong(StrongNode node) => _buildNodes(node.nodes,
style: weightVariableTextStyle(_context!, wght: 600));
InlineSpan _buildStrong(StrongNode node) =>
_buildNodes(style: bolderWghtTextStyle(widget.style, by: 200),
node.nodes);

InlineSpan _buildDeleted(DeletedNode node) => _buildNodes(node.nodes,
style: const TextStyle(decoration: TextDecoration.lineThrough));
Expand Down
48 changes: 48 additions & 0 deletions test/widgets/content_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,54 @@ void main() {
content: plainContent('<p><strong>bold</strong></p>'),
styleFinder: findWordBold,
);

for (final level in HeadingLevel.values) {
final name = level.name;
assert(RegExp(r'^h[1-6]$').hasMatch(name));
testFontWeight('in $name',
expectedWght: 800,
// # **bold**, ## **bold**, ### **bold**, etc.
content: plainContent('<$name><strong>bold</strong></$name>'),
styleFinder: findWordBold,
);
}

testFontWeight('in different kind of span in h1',
expectedWght: 800,
// # ~~**bold**~~
content: plainContent('<h1><del><strong>bold</strong></del></h1>'),
styleFinder: findWordBold,
);

testFontWeight('in spoiler header',
expectedWght: 900,
// ```spoiler regular **bold**
// content
// ```
content: plainContent(
'<div class="spoiler-block"><div class="spoiler-header">\n'
'<p>regular <strong>bold</strong></p>\n'
'</div><div class="spoiler-content" aria-hidden="true">\n'
'<p>content</p>\n'
'</div></div>'
),
styleFinder: findWordBold,
);

testFontWeight('in different kind of span in spoiler header',
expectedWght: 900,
// ```spoiler *italic **bold***
// content
// ```
content: plainContent(
'<div class="spoiler-block"><div class="spoiler-header">\n'
'<p><em>italic <strong>bold</strong></em></p>\n'
'</div><div class="spoiler-content" aria-hidden="true">\n'
'<p>content</p>\n'
'</div></div>'
),
styleFinder: findWordBold,
);
});

testContentSmoke(ContentExample.emphasis);
Expand Down

0 comments on commit 61754f7

Please sign in to comment.