Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/flutter_markdown/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.18+4

* Allow for choosing custom font feature to create superscript in footnotes when the font does not support `supr` font feature. Use `superscriptFontFeatureTag` property in `MarkdownStyleSheet`. For example for `Roboto` font you can set `numr`.

## 0.6.18+3

* Updates minimum supported SDK version to Flutter 3.10/Dart 3.0.
Expand Down
2 changes: 2 additions & 0 deletions packages/flutter_markdown/lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,8 @@ class MarkdownBuilder implements md.NodeVisitor {
style: textSpan.style?.copyWith(
fontFeatures: <FontFeature>[
const FontFeature.enable('sups'),
if (styleSheet.superscriptFontFeatureTag != null)
FontFeature.enable(styleSheet.superscriptFontFeatureTag!),
],
),
),
Expand Down
13 changes: 12 additions & 1 deletion packages/flutter_markdown/lib/src/style_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class MarkdownStyleSheet {
this.blockquoteAlign = WrapAlignment.start,
this.codeblockAlign = WrapAlignment.start,
this.textScaleFactor,
this.superscriptFontFeatureTag,
}) : _styles = <String, TextStyle?>{
'a': a,
'p': p,
Expand Down Expand Up @@ -381,6 +382,7 @@ class MarkdownStyleSheet {
WrapAlignment? blockquoteAlign,
WrapAlignment? codeblockAlign,
double? textScaleFactor,
String? superscriptFontFeatureTag,
}) {
return MarkdownStyleSheet(
a: a ?? this.a,
Expand Down Expand Up @@ -436,6 +438,8 @@ class MarkdownStyleSheet {
blockquoteAlign: blockquoteAlign ?? this.blockquoteAlign,
codeblockAlign: codeblockAlign ?? this.codeblockAlign,
textScaleFactor: textScaleFactor ?? this.textScaleFactor,
superscriptFontFeatureTag:
superscriptFontFeatureTag ?? this.superscriptFontFeatureTag,
);
}

Expand Down Expand Up @@ -497,6 +501,7 @@ class MarkdownStyleSheet {
blockquoteAlign: other.blockquoteAlign,
codeblockAlign: other.codeblockAlign,
textScaleFactor: other.textScaleFactor,
superscriptFontFeatureTag: other.superscriptFontFeatureTag,
);
}

Expand Down Expand Up @@ -653,6 +658,10 @@ class MarkdownStyleSheet {
/// The text scale factor to use in textual elements
final double? textScaleFactor;

/// Custom font feature tag for font which does not support `sups'
/// feature to create superscript in footnotes.
final String? superscriptFontFeatureTag;

/// A [Map] from element name to the corresponding [TextStyle] object.
Map<String, TextStyle?> get styles => _styles;
Map<String, TextStyle?> _styles;
Expand Down Expand Up @@ -717,7 +726,8 @@ class MarkdownStyleSheet {
other.orderedListAlign == orderedListAlign &&
other.blockquoteAlign == blockquoteAlign &&
other.codeblockAlign == codeblockAlign &&
other.textScaleFactor == textScaleFactor;
other.textScaleFactor == textScaleFactor &&
other.superscriptFontFeatureTag == superscriptFontFeatureTag;
}

@override
Expand Down Expand Up @@ -775,6 +785,7 @@ class MarkdownStyleSheet {
blockquoteAlign,
codeblockAlign,
textScaleFactor,
superscriptFontFeatureTag,
]);
}
}
2 changes: 1 addition & 1 deletion packages/flutter_markdown/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: A Markdown renderer for Flutter. Create rich text output,
formatted with simple Markdown tags.
repository: https://github.com/flutter/packages/tree/main/packages/flutter_markdown
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_markdown%22
version: 0.6.18+3
version: 0.6.18+4

environment:
sdk: ">=3.0.0 <4.0.0"
Expand Down
31 changes: 30 additions & 1 deletion packages/flutter_markdown/test/footnote_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void defineTests() {
'superscript textstyle replacing',
() {
testWidgets(
'superscript has correct fontfeature',
'superscript has correct default fontfeature',
(WidgetTester tester) async {
const String data = 'Foo[^a]\n[^a]: Bar';
await tester.pumpWidget(
Expand All @@ -184,6 +184,35 @@ void defineTests() {
},
);

testWidgets(
'superscript has correct custom fontfeature',
(WidgetTester tester) async {
const String data = 'Foo[^a]\n[^a]: Bar';
await tester.pumpWidget(
boilerplate(
MarkdownBody(
data: data,
styleSheet:
MarkdownStyleSheet(superscriptFontFeatureTag: 'numr'),
),
),
);

final Iterable<Widget> widgets = tester.allWidgets;
final RichText richText = widgets
.firstWhere((Widget widget) => widget is RichText) as RichText;

final TextSpan span = richText.text as TextSpan;
final List<InlineSpan>? children = span.children;

expect(children, isNotNull);
expect(children!.length, 2);
expect(children[1].style, isNotNull);
expect(children[1].style!.fontFeatures?.length, 2);
expect(children[1].style!.fontFeatures?[1].feature, 'numr');
},
);

testWidgets(
'superscript index has the same font style like text',
(WidgetTester tester) async {
Expand Down