Skip to content

Commit afb3692

Browse files
committed
katex [nfc]: On KatexSpanNode constructor let text or nodes be omitted
We already have an assert enforcing that exactly one of these is passed with a non-null (i.e. non-default) value. So there's no risk of forgetting to specify a detail that should be specified.
1 parent 182ac54 commit afb3692

File tree

4 files changed

+109
-118
lines changed

4 files changed

+109
-118
lines changed

lib/model/content.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,8 @@ sealed class KatexNode extends ContentNode {
381381
class KatexSpanNode extends KatexNode {
382382
const KatexSpanNode({
383383
required this.styles,
384-
required this.text,
385-
required this.nodes,
384+
this.text,
385+
this.nodes,
386386
super.debugHtmlNode,
387387
}) : assert((text != null) ^ (nodes != null));
388388

lib/model/katex.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,11 @@ class _KatexParser {
341341

342342
KatexSpanNode child = KatexSpanNode(
343343
styles: styles,
344-
text: null,
345344
nodes: _parseChildSpans(otherSpans));
346345

347346
if (marginLeftIsNegative) {
348347
child = KatexSpanNode(
349348
styles: KatexSpanStyles(),
350-
text: null,
351349
nodes: [KatexNegativeMarginNode(
352350
leftOffsetEm: marginLeftEm!,
353351
nodes: [child])]);

test/model/content_test.dart

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -518,14 +518,13 @@ class ContentExample {
518518
'<annotation encoding="application/x-tex"> \\lambda </annotation></semantics></math></span>'
519519
'<span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">λ</span></span></span></span></p>',
520520
MathInlineNode(texSource: r'\lambda', nodes: [
521-
KatexSpanNode(styles: KatexSpanStyles(), text: null, nodes: [
521+
KatexSpanNode(styles: KatexSpanStyles(), nodes: [
522522
KatexStrutNode(heightEm: 0.6944, verticalAlignEm: null),
523523
KatexSpanNode(
524524
styles: KatexSpanStyles(
525525
fontFamily: 'KaTeX_Math',
526526
fontStyle: KatexSpanFontStyle.italic),
527-
text: 'λ',
528-
nodes: null),
527+
text: 'λ'),
529528
]),
530529
]));
531530

@@ -538,14 +537,13 @@ class ContentExample {
538537
'<annotation encoding="application/x-tex">\\lambda</annotation></semantics></math></span>'
539538
'<span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">λ</span></span></span></span></span></p>',
540539
[MathBlockNode(texSource: r'\lambda', nodes: [
541-
KatexSpanNode(styles: KatexSpanStyles(), text: null, nodes: [
540+
KatexSpanNode(styles: KatexSpanStyles(), nodes: [
542541
KatexStrutNode(heightEm: 0.6944, verticalAlignEm: null),
543542
KatexSpanNode(
544543
styles: KatexSpanStyles(
545544
fontFamily: 'KaTeX_Math',
546545
fontStyle: KatexSpanFontStyle.italic),
547-
text: 'λ',
548-
nodes: null),
546+
text: 'λ'),
549547
]),
550548
])]);
551549

@@ -563,25 +561,23 @@ class ContentExample {
563561
'<annotation encoding="application/x-tex">b</annotation></semantics></math></span>'
564562
'<span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">b</span></span></span></span></span></p>', [
565563
MathBlockNode(texSource: 'a', nodes: [
566-
KatexSpanNode(styles: KatexSpanStyles(), text: null, nodes: [
564+
KatexSpanNode(styles: KatexSpanStyles(), nodes: [
567565
KatexStrutNode(heightEm: 0.4306, verticalAlignEm: null),
568566
KatexSpanNode(
569567
styles: KatexSpanStyles(
570568
fontFamily: 'KaTeX_Math',
571569
fontStyle: KatexSpanFontStyle.italic),
572-
text: 'a',
573-
nodes: null),
570+
text: 'a'),
574571
]),
575572
]),
576573
MathBlockNode(texSource: 'b', nodes: [
577-
KatexSpanNode(styles: KatexSpanStyles(), text: null, nodes: [
574+
KatexSpanNode(styles: KatexSpanStyles(), nodes: [
578575
KatexStrutNode(heightEm: 0.6944, verticalAlignEm: null),
579576
KatexSpanNode(
580577
styles: KatexSpanStyles(
581578
fontFamily: 'KaTeX_Math',
582579
fontStyle: KatexSpanFontStyle.italic),
583-
text: 'b',
584-
nodes: null),
580+
text: 'b'),
585581
]),
586582
]),
587583
]);
@@ -602,14 +598,13 @@ class ContentExample {
602598
'<br>\n</p>\n</blockquote>',
603599
[QuotationNode([
604600
MathBlockNode(texSource: r'\lambda', nodes: [
605-
KatexSpanNode(styles: KatexSpanStyles(), text: null, nodes: [
601+
KatexSpanNode(styles: KatexSpanStyles(), nodes: [
606602
KatexStrutNode(heightEm: 0.6944, verticalAlignEm: null),
607603
KatexSpanNode(
608604
styles: KatexSpanStyles(
609605
fontFamily: 'KaTeX_Math',
610606
fontStyle: KatexSpanFontStyle.italic),
611-
text: 'λ',
612-
nodes: null),
607+
text: 'λ'),
613608
]),
614609
]),
615610
])]);
@@ -631,25 +626,23 @@ class ContentExample {
631626
'<br>\n</p>\n</blockquote>',
632627
[QuotationNode([
633628
MathBlockNode(texSource: 'a', nodes: [
634-
KatexSpanNode(styles: KatexSpanStyles(), text: null, nodes: [
629+
KatexSpanNode(styles: KatexSpanStyles(), nodes: [
635630
KatexStrutNode(heightEm: 0.4306, verticalAlignEm: null),
636631
KatexSpanNode(
637632
styles: KatexSpanStyles(
638633
fontFamily: 'KaTeX_Math',
639634
fontStyle: KatexSpanFontStyle.italic),
640-
text: 'a',
641-
nodes: null),
635+
text: 'a'),
642636
]),
643637
]),
644638
MathBlockNode(texSource: 'b', nodes: [
645-
KatexSpanNode(styles: KatexSpanStyles(), text: null, nodes: [
639+
KatexSpanNode(styles: KatexSpanStyles(), nodes: [
646640
KatexStrutNode(heightEm: 0.6944, verticalAlignEm: null),
647641
KatexSpanNode(
648642
styles: KatexSpanStyles(
649643
fontFamily: 'KaTeX_Math',
650644
fontStyle: KatexSpanFontStyle.italic),
651-
text: 'b',
652-
nodes: null),
645+
text: 'b'),
653646
]),
654647
]),
655648
])]);
@@ -680,13 +673,13 @@ class ContentExample {
680673
originalHeight: null),
681674
]),
682675
MathBlockNode(texSource: 'a', nodes: [
683-
KatexSpanNode(styles: KatexSpanStyles(), text: null, nodes: [
676+
KatexSpanNode(styles: KatexSpanStyles(), nodes: [
684677
KatexStrutNode(heightEm: 0.4306, verticalAlignEm: null),
685678
KatexSpanNode(
686679
styles: KatexSpanStyles(
687680
fontFamily: 'KaTeX_Math',
688681
fontStyle: KatexSpanFontStyle.italic),
689-
text: 'a', nodes: null),
682+
text: 'a'),
690683
]),
691684
]),
692685
ImageNodeList([

0 commit comments

Comments
 (0)