Skip to content

Commit 460d426

Browse files
katex: Add CSS support for overline and underline borders.
Adds parsing and styling support for the overline-line and underline-line CSS classes used in KaTeX rendering. These classes apply a solid border-bottom-style to create the visual line effect. The implementation adds: - KatexSpanBorderBottomStyle enum for border style values - borderBottomStyle and borderBottomWidthEm fields to KatexSpanStyles - Parsing of overline-line/underline-line classes from KaTeX HTML - Support for border-bottom-width inline style property The overline and underline base classes are now explicitly ignored in parsing, as they don't have CSS definitions in katex.scss but appear in the generated HTML for semantic purposes.
1 parent 134b091 commit 460d426

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

lib/model/katex.dart

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ class _KatexParser {
411411
KatexSpanFontWeight? fontWeight;
412412
KatexSpanFontStyle? fontStyle;
413413
KatexSpanTextAlign? textAlign;
414+
KatexSpanBorderBottomStyle? borderBottomStyle;
414415
var index = 0;
415416
while (index < spanClasses.length) {
416417
final spanClass = spanClasses[index++];
@@ -626,6 +627,8 @@ class _KatexParser {
626627
case 'nobreak':
627628
case 'allowbreak':
628629
case 'mathdefault':
630+
case 'overline':
631+
case 'underline':
629632
// Ignore these classes because they don't have a CSS definition
630633
// in katex.scss, but we encounter them in the generated HTML.
631634
// (Why are they there if they're not used? The story seems to be:
@@ -636,6 +639,14 @@ class _KatexParser {
636639
// )
637640
break;
638641

642+
case 'overline-line':
643+
case 'underline-line':
644+
// .underline-line { width: 100%; border-bottom-style: solid; }
645+
// Border applied via inline style: border-bottom-width: 0.04em;
646+
widthEm = double.infinity;
647+
borderBottomStyle = KatexSpanBorderBottomStyle.solid;
648+
break;
649+
639650
default:
640651
assert(debugLog('KaTeX: Unsupported CSS class: $spanClass'));
641652
unsupportedCssClasses.add(spanClass);
@@ -657,10 +668,14 @@ class _KatexParser {
657668
marginRightEm: _takeStyleEm(inlineStyles, 'margin-right'),
658669
color: _takeStyleColor(inlineStyles, 'color'),
659670
position: _takeStylePosition(inlineStyles, 'position'),
671+
borderBottomStyle: borderBottomStyle,
672+
borderBottomWidthEm: _takeStyleEm(inlineStyles, 'border-bottom-width')
660673
// TODO handle more CSS properties
661674
);
662675
if (inlineStyles != null && inlineStyles.isNotEmpty) {
663676
for (final property in inlineStyles.keys) {
677+
// Ignore known properties that don't need special handling
678+
if (property == 'width' || property == 'min-width' || property == 'border-bottom-width') {continue;}
664679
assert(debugLog('KaTeX: Unexpected inline CSS property: $property'));
665680
unsupportedInlineCssProperties.add(property);
666681
_hasError = true;
@@ -840,6 +855,10 @@ enum KatexSpanPosition {
840855
relative,
841856
}
842857

858+
enum KatexSpanBorderBottomStyle {
859+
solid,
860+
}
861+
843862
class KatexSpanColor {
844863
const KatexSpanColor(this.r, this.g, this.b, this.a);
845864

@@ -893,6 +912,8 @@ class KatexSpanStyles {
893912

894913
final KatexSpanColor? color;
895914
final KatexSpanPosition? position;
915+
final KatexSpanBorderBottomStyle? borderBottomStyle;
916+
final double? borderBottomWidthEm;
896917

897918
const KatexSpanStyles({
898919
this.widthEm,
@@ -907,6 +928,8 @@ class KatexSpanStyles {
907928
this.textAlign,
908929
this.color,
909930
this.position,
931+
this.borderBottomStyle,
932+
this.borderBottomWidthEm,
910933
});
911934

912935
@override
@@ -924,6 +947,8 @@ class KatexSpanStyles {
924947
textAlign,
925948
color,
926949
position,
950+
borderBottomStyle,
951+
borderBottomWidthEm
927952
);
928953

929954
@override
@@ -940,7 +965,9 @@ class KatexSpanStyles {
940965
other.fontStyle == fontStyle &&
941966
other.textAlign == textAlign &&
942967
other.color == color &&
943-
other.position == position;
968+
other.position == position &&
969+
other.borderBottomStyle == borderBottomStyle &&
970+
other.borderBottomWidthEm == borderBottomWidthEm;
944971
}
945972

946973
@override
@@ -958,6 +985,8 @@ class KatexSpanStyles {
958985
if (textAlign != null) args.add('textAlign: $textAlign');
959986
if (color != null) args.add('color: $color');
960987
if (position != null) args.add('position: $position');
988+
if (borderBottomStyle != null) args.add('borderBottomStyle: $borderBottomStyle');
989+
if (borderBottomWidthEm != null) args.add('borderBottomWidthEm: $borderBottomWidthEm');
961990
return '${objectRuntimeType(this, 'KatexSpanStyles')}(${args.join(', ')})';
962991
}
963992

@@ -975,6 +1004,8 @@ class KatexSpanStyles {
9751004
bool textAlign = true,
9761005
bool color = true,
9771006
bool position = true,
1007+
bool borderBottomStyle = true,
1008+
bool borderBottomWidthEm = true,
9781009
}) {
9791010
return KatexSpanStyles(
9801011
widthEm: widthEm ? this.widthEm : null,
@@ -989,6 +1020,8 @@ class KatexSpanStyles {
9891020
textAlign: textAlign ? this.textAlign : null,
9901021
color: color ? this.color : null,
9911022
position: position ? this.position : null,
1023+
borderBottomStyle: borderBottomStyle ? this.borderBottomStyle : null,
1024+
borderBottomWidthEm: borderBottomWidthEm ? this.borderBottomWidthEm : null,
9921025
);
9931026
}
9941027
}

0 commit comments

Comments
 (0)