Skip to content

Commit 113e3dc

Browse files
content: Handle 'top' property in KaTeX span inline style
1 parent c8558fb commit 113e3dc

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
@@ -493,6 +493,7 @@ class _KatexParser {
493493
if (stylesheet.topLevels case [css_visitor.RuleSet() && final rule]) {
494494
double? heightEm;
495495
double? verticalAlignEm;
496+
double? topEm;
496497
double? marginRightEm;
497498
double? marginLeftEm;
498499

@@ -511,6 +512,10 @@ class _KatexParser {
511512
verticalAlignEm = _getEm(expression);
512513
if (verticalAlignEm != null) continue;
513514

515+
case 'top':
516+
topEm = _getEm(expression);
517+
if (topEm != null) continue;
518+
514519
case 'margin-right':
515520
marginRightEm = _getEm(expression);
516521
if (marginRightEm != null) {
@@ -538,6 +543,7 @@ class _KatexParser {
538543

539544
return KatexSpanStyles(
540545
heightEm: heightEm,
546+
topEm: topEm,
541547
verticalAlignEm: verticalAlignEm,
542548
marginRightEm: marginRightEm,
543549
marginLeftEm: marginLeftEm,
@@ -579,6 +585,8 @@ class KatexSpanStyles {
579585
final double? heightEm;
580586
final double? verticalAlignEm;
581587

588+
final double? topEm;
589+
582590
final double? marginRightEm;
583591
final double? marginLeftEm;
584592

@@ -591,6 +599,7 @@ class KatexSpanStyles {
591599
const KatexSpanStyles({
592600
this.heightEm,
593601
this.verticalAlignEm,
602+
this.topEm,
594603
this.marginRightEm,
595604
this.marginLeftEm,
596605
this.fontFamily,
@@ -605,6 +614,7 @@ class KatexSpanStyles {
605614
'KatexSpanStyles',
606615
heightEm,
607616
verticalAlignEm,
617+
topEm,
608618
marginRightEm,
609619
marginLeftEm,
610620
fontFamily,
@@ -619,6 +629,7 @@ class KatexSpanStyles {
619629
return other is KatexSpanStyles &&
620630
other.heightEm == heightEm &&
621631
other.verticalAlignEm == verticalAlignEm &&
632+
other.topEm == topEm &&
622633
other.marginRightEm == marginRightEm &&
623634
other.marginLeftEm == marginLeftEm &&
624635
other.fontFamily == fontFamily &&
@@ -633,6 +644,7 @@ class KatexSpanStyles {
633644
final args = <String>[];
634645
if (heightEm != null) args.add('heightEm: $heightEm');
635646
if (verticalAlignEm != null) args.add('verticalAlignEm: $verticalAlignEm');
647+
if (topEm != null) args.add('topEm: $topEm');
636648
if (marginRightEm != null) args.add('marginRightEm: $marginRightEm');
637649
if (marginLeftEm != null) args.add('marginLeftEm: $marginLeftEm');
638650
if (fontFamily != null) args.add('fontFamily: $fontFamily');
@@ -654,6 +666,7 @@ class KatexSpanStyles {
654666
return KatexSpanStyles(
655667
heightEm: other.heightEm ?? heightEm,
656668
verticalAlignEm: other.verticalAlignEm ?? verticalAlignEm,
669+
topEm: other.topEm ?? topEm,
657670
marginRightEm: other.marginRightEm ?? marginRightEm,
658671
marginLeftEm: other.marginLeftEm ?? marginLeftEm,
659672
fontFamily: other.fontFamily ?? fontFamily,
@@ -667,6 +680,7 @@ class KatexSpanStyles {
667680
KatexSpanStyles filter({
668681
bool heightEm = true,
669682
bool verticalAlignEm = true,
683+
bool topEm = true,
670684
bool marginRightEm = true,
671685
bool marginLeftEm = true,
672686
bool fontFamily = true,
@@ -678,6 +692,7 @@ class KatexSpanStyles {
678692
return KatexSpanStyles(
679693
heightEm: heightEm ? this.heightEm : null,
680694
verticalAlignEm: verticalAlignEm ? this.verticalAlignEm : null,
695+
topEm: topEm ? this.topEm : null,
681696
marginRightEm: marginRightEm ? this.marginRightEm : null,
682697
marginLeftEm: marginLeftEm ? this.marginLeftEm : null,
683698
fontFamily: fontFamily ? this.fontFamily : null,

lib/widgets/content.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,9 @@ class _KatexSpan extends StatelessWidget {
981981
height: styles.heightEm != null
982982
? styles.heightEm! * (fontSize ?? em)
983983
: null,
984+
transform: styles.topEm != null
985+
? Matrix4.translationValues(0, styles.topEm! * em, 0)
986+
: null,
984987
child: widget);
985988
}
986989
}

0 commit comments

Comments
 (0)