From 61754f7b6d4043b4cb36b9471f4bf469dab7464c Mon Sep 17 00:00:00 2001 From: Chris Bobbe Date: Wed, 22 May 2024 15:58:18 -0700 Subject: [PATCH] content: Make **bold** bolder even in spoiler headers and h1/h2/etc. Fixes: #705 --- lib/widgets/content.dart | 12 +++++++-- test/widgets/content_test.dart | 48 ++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/lib/widgets/content.dart b/lib/widgets/content.dart index 9e7008aca1..92e04ff9f4 100644 --- a/lib/widgets/content.dart +++ b/lib/widgets/content.dart @@ -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); } @@ -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 nodes; @@ -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)); diff --git a/test/widgets/content_test.dart b/test/widgets/content_test.dart index 9e654f22e5..c44ae088c4 100644 --- a/test/widgets/content_test.dart +++ b/test/widgets/content_test.dart @@ -519,6 +519,54 @@ void main() { content: plainContent('

bold

'), 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>bold'), + styleFinder: findWordBold, + ); + } + + testFontWeight('in different kind of span in h1', + expectedWght: 800, + // # ~~**bold**~~ + content: plainContent('

bold

'), + styleFinder: findWordBold, + ); + + testFontWeight('in spoiler header', + expectedWght: 900, + // ```spoiler regular **bold** + // content + // ``` + content: plainContent( + '
\n' + '

regular bold

\n' + '
' + ), + styleFinder: findWordBold, + ); + + testFontWeight('in different kind of span in spoiler header', + expectedWght: 900, + // ```spoiler *italic **bold*** + // content + // ``` + content: plainContent( + '
\n' + '

italic bold

\n' + '
' + ), + styleFinder: findWordBold, + ); }); testContentSmoke(ContentExample.emphasis);