Skip to content

Commit d513bfc

Browse files
content: Handle 'top' property in KaTeX span inline style
1 parent 3426600 commit d513bfc

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/model/katex.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ class _KatexParser {
424424
if (stylesheet.topLevels case [css_visitor.RuleSet() && final rule]) {
425425
double? heightEm;
426426
double? verticalAlignEm;
427+
double? topEm;
427428
double? marginRightEm;
428429
double? marginLeftEm;
429430

@@ -442,6 +443,10 @@ class _KatexParser {
442443
verticalAlignEm = _getEm(expression);
443444
if (verticalAlignEm != null) continue;
444445

446+
case 'top':
447+
topEm = _getEm(expression);
448+
if (topEm != null) continue;
449+
445450
case 'margin-right':
446451
marginRightEm = _getEm(expression);
447452
if (marginRightEm != null) {
@@ -468,6 +473,7 @@ class _KatexParser {
468473

469474
return KatexSpanStyles(
470475
heightEm: heightEm,
476+
topEm: topEm,
471477
verticalAlignEm: verticalAlignEm,
472478
marginRightEm: marginRightEm,
473479
marginLeftEm: marginLeftEm,
@@ -509,6 +515,8 @@ class KatexSpanStyles {
509515
final double? heightEm;
510516
final double? verticalAlignEm;
511517

518+
final double? topEm;
519+
512520
final double? marginRightEm;
513521
final double? marginLeftEm;
514522

@@ -521,6 +529,7 @@ class KatexSpanStyles {
521529
const KatexSpanStyles({
522530
this.heightEm,
523531
this.verticalAlignEm,
532+
this.topEm,
524533
this.marginRightEm,
525534
this.marginLeftEm,
526535
this.fontFamily,
@@ -535,6 +544,7 @@ class KatexSpanStyles {
535544
'KatexSpanStyles',
536545
heightEm,
537546
verticalAlignEm,
547+
topEm,
538548
marginRightEm,
539549
marginLeftEm,
540550
fontFamily,
@@ -549,6 +559,7 @@ class KatexSpanStyles {
549559
return other is KatexSpanStyles &&
550560
other.heightEm == heightEm &&
551561
other.verticalAlignEm == verticalAlignEm &&
562+
other.topEm == topEm &&
552563
other.marginRightEm == marginRightEm &&
553564
other.marginLeftEm == marginLeftEm &&
554565
other.fontFamily == fontFamily &&
@@ -563,6 +574,7 @@ class KatexSpanStyles {
563574
final args = <String>[];
564575
if (heightEm != null) args.add('heightEm: $heightEm');
565576
if (verticalAlignEm != null) args.add('verticalAlignEm: $verticalAlignEm');
577+
if (topEm != null) args.add('topEm: $topEm');
566578
if (marginRightEm != null) args.add('marginRightEm: $marginRightEm');
567579
if (marginLeftEm != null) args.add('marginLeftEm: $marginLeftEm');
568580
if (fontFamily != null) args.add('fontFamily: $fontFamily');
@@ -577,6 +589,7 @@ class KatexSpanStyles {
577589
return KatexSpanStyles(
578590
heightEm: other.heightEm ?? heightEm,
579591
verticalAlignEm: other.verticalAlignEm ?? verticalAlignEm,
592+
topEm: other.topEm ?? topEm,
580593
marginRightEm: other.marginRightEm ?? marginRightEm,
581594
marginLeftEm: other.marginLeftEm ?? marginLeftEm,
582595
fontFamily: other.fontFamily ?? fontFamily,
@@ -590,6 +603,7 @@ class KatexSpanStyles {
590603
KatexSpanStyles filter({
591604
bool heightEm = true,
592605
bool verticalAlignEm = true,
606+
bool topEm = true,
593607
bool marginRightEm = true,
594608
bool marginLeftEm = true,
595609
bool fontFamily = true,
@@ -601,6 +615,7 @@ class KatexSpanStyles {
601615
return KatexSpanStyles(
602616
heightEm: heightEm ? this.heightEm : null,
603617
verticalAlignEm: verticalAlignEm ? this.verticalAlignEm : null,
618+
topEm: topEm ? this.topEm : null,
604619
marginRightEm: marginRightEm ? this.marginRightEm : null,
605620
marginLeftEm: marginLeftEm ? this.marginLeftEm : null,
606621
fontFamily: fontFamily ? this.fontFamily : null,

lib/widgets/content.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,9 @@ class _KatexSpan extends StatelessWidget {
986986
height: styles.heightEm != null
987987
? styles.heightEm! * em
988988
: null,
989+
transform: styles.topEm != null
990+
? Matrix4.translationValues(0, styles.topEm! * em, 0)
991+
: null,
989992
child: widget,
990993
);
991994
}

0 commit comments

Comments
 (0)