Skip to content

Commit

Permalink
content: Make h1 font weight combine with spoiler-header font weight
Browse files Browse the repository at this point in the history
This doesn't seem super important (putting h1 in a spoiler header is
basically an Easter egg), but it's something we're able to do, so
might as well.
  • Loading branch information
chrisbobbe committed May 31, 2024
1 parent 61754f7 commit 24a0036
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/widgets/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,15 @@ class Heading extends StatelessWidget {
HeadingLevel.h5 => 1.05,
HeadingLevel.h6 => 1.0,
};
final ambientTextStyle = DefaultTextStyle.of(context).style;
return Padding(
padding: const EdgeInsets.only(top: 15, bottom: 5),
child: _buildBlockInlineContainer(
style: TextStyle(
fontSize: kBaseFontSize * emHeight,
height: 1.4,
)
.merge(weightVariableTextStyle(context, wght: 600)),
style: bolderWghtTextStyle(ambientTextStyle, by: 200)
.merge(TextStyle(
fontSize: kBaseFontSize * emHeight,
height: 1.4,
)),
node: node));
}
}
Expand Down
34 changes: 34 additions & 0 deletions test/widgets/content_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,25 @@ void main() {
plainContent('<h1>one</h1>\n<h2>two</h2>\n<h3>three</h3>\n<h4>four</h4>\n<h5>five</h5>'));
check(find.byType(Heading).evaluate()).length.equals(5);
});

testFontWeight('h1 in spoiler header',
expectedWght: 900,
// ```spoiler # h1
// content
// ```
content: plainContent(
'<div class="spoiler-block"><div class="spoiler-header">\n'
'<h1>h1</h1>\n'
'</div><div class="spoiler-content" aria-hidden="true">\n'
'<p>content</p>\n'
'</div></div>'

),
styleFinder: (tester) {
final root = tester.renderObject<RenderParagraph>(find.textContaining('h1')).text;
return mergedStyleOfSubstring(root, 'h1')!;
},
);
});

group('Spoiler', () {
Expand Down Expand Up @@ -567,6 +586,21 @@ void main() {
),
styleFinder: findWordBold,
);

testFontWeight('in h1 in spoiler header',
expectedWght: 1000,
// ```spoiler # h1: regular **bold**
// content
// ```
content: plainContent(
'<div class="spoiler-block"><div class="spoiler-header">\n'
'<h1>h1: regular <strong>bold</strong></h1>\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 24a0036

Please sign in to comment.