Skip to content
Next Next commit
[flutter_markdown] allow to choose custom font feature for superscript
  • Loading branch information
dawidope committed Jan 11, 2024
commit 46ab6665b9448677342d61dabd67804dcbb93eee
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,
]);
}
}