Skip to content

Commit 0fe4f77

Browse files
committed
content: Remove TextStyle merge in rendering inline code
Also in rendering inline TeX source when it doesn't parse...but that's decreasingly visible as we implement more TeX. :) Fixes #806. Fixes #1812. Similar reasoning as in the previous commits; see there. The inline-code span-node was clobbering the link-color and font-weight attributes when those are set by ancestor link and emphasis nodes.
1 parent 969f480 commit 0fe4f77

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

lib/widgets/content.dart

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,9 +1137,8 @@ class _InlineContentBuilder {
11371137
final nodes = node.nodes;
11381138
return nodes == null
11391139
? TextSpan(
1140-
style: widget.style
1141-
.merge(ContentTheme.of(_context!).textStyleInlineMath)
1142-
.apply(fontSizeFactor: kInlineCodeFontSizeFactor),
1140+
style: ContentTheme.of(_context!).textStyleInlineMath
1141+
.copyWith(fontSize: widget.style.fontSize! * kInlineCodeFontSizeFactor),
11431142
children: [TextSpan(text: node.texSource)])
11441143
: WidgetSpan(
11451144
alignment: PlaceholderAlignment.baseline,
@@ -1180,11 +1179,9 @@ class _InlineContentBuilder {
11801179
// TODO `code`: find equivalent of web's `unicode-bidi: embed; direction: ltr`
11811180

11821181
return _buildNodes(
1183-
style: widget.style
1184-
.merge(ContentTheme.of(_context!).textStyleInlineCode)
1185-
.apply(fontSizeFactor: kInlineCodeFontSizeFactor),
1186-
node.nodes,
1187-
);
1182+
style: ContentTheme.of(_context!).textStyleInlineCode
1183+
.copyWith(fontSize: widget.style.fontSize! * kInlineCodeFontSizeFactor),
1184+
node.nodes);
11881185

11891186
// Another fun solution -- we can in fact have a border! Like so:
11901187
// TextStyle(

test/widgets/content_test.dart

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,22 @@ void main() {
729729
targetHtml: '<code>code</code>',
730730
targetFontSizeFinder: mkTargetFontSizeFinderFromPattern('code'));
731731
});
732+
733+
testFontWeight('is bold in bold span',
734+
// Regression test for: https://github.com/zulip/zulip-flutter/issues/1812
735+
expectedWght: 600,
736+
// **`bold`**
737+
content: plainContent('<p><strong><code>bold</code></strong></p>'),
738+
styleFinder: (tester) => mergedStyleOf(tester, 'bold')!,
739+
);
740+
741+
testWidgets('is link-colored in link span', (tester) async {
742+
// Regression test for: https://github.com/zulip/zulip-flutter/issues/806
743+
await prepareContent(tester,
744+
plainContent('<p><a href="https://example/"><code>code</code></a></p>'));
745+
final style = mergedStyleOf(tester, 'code');
746+
check(style!.color).equals(const HSLColor.fromAHSL(1, 200, 1, 0.4).toColor());
747+
});
732748
});
733749

734750
group('UserMention', () {
@@ -1046,8 +1062,29 @@ void main() {
10461062
tester.widget(find.text('λ', findRichText: true));
10471063
});
10481064

1049-
testWidgets('fallback to displaying KaTeX source if unsupported KaTeX HTML', (tester) async {
1065+
group('fallback to displaying KaTeX source if unsupported KaTeX HTML', () {
10501066
testContentSmoke(ContentExample.mathInlineUnknown);
1067+
1068+
assert(ContentExample.mathInlineUnknown.html.startsWith('<p>'));
1069+
assert(ContentExample.mathInlineUnknown.html.endsWith('</p>'));
1070+
final unsupportedKatexHtml = ContentExample.mathInlineUnknown.html
1071+
.substring(3, ContentExample.mathInlineUnknown.html.length - 4);
1072+
1073+
testFontWeight('is bold in bold span',
1074+
// Regression test for: https://github.com/zulip/zulip-flutter/issues/1812
1075+
expectedWght: 600,
1076+
// **$$ \lambda $$**
1077+
content: plainContent('<p><strong>$unsupportedKatexHtml</strong></p>'),
1078+
styleFinder: (tester) => mergedStyleOf(tester, r'\lambda')!,
1079+
);
1080+
1081+
testWidgets('is link-colored in link span', (tester) async {
1082+
// Regression test for: https://github.com/zulip/zulip-flutter/issues/806
1083+
await prepareContent(tester,
1084+
plainContent('<p><a href="https://example/">$unsupportedKatexHtml</a></p>'));
1085+
final style = mergedStyleOf(tester, r'\lambda');
1086+
check(style!.color).equals(const HSLColor.fromAHSL(1, 200, 1, 0.4).toColor());
1087+
});
10511088
});
10521089
});
10531090

0 commit comments

Comments
 (0)