Skip to content

Commit 11c2624

Browse files
authored
Fix tabs in list (#578)
* Fix tabs in list * format * Fix tests * Remove unused imports * Update src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs
1 parent cad0ef0 commit 11c2624

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

src/Elastic.Markdown/Assets/markdown/list.css

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@
3737
ol>li>ol>li>ol>li>ol>li>ol>li>ol { list-style-type: lower-roman; }
3838

3939
/* Special handling of elements within a list item */
40-
li>p:nth-child(2),
41-
li>div>.highlight,
42-
li>.admonition
40+
li>*:first-child,
41+
li>p:nth-child(2)
4342
{
4443
@apply mt-1;
4544
}
45+
li>p:first-child
46+
{
47+
@apply mt-4;
48+
}
4649
}

src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,20 @@ public class TabSetBlock(DirectiveBlockParser parser, ParserContext context)
1818
public override void FinalizeAndValidate(ParserContext context) => Index = FindIndex();
1919

2020
private int _index = -1;
21+
22+
// For simplicity, we use the line number as the index.
23+
// It's not ideal, but it's unique.
24+
// This is more efficient than finding the root block and then finding the index.
2125
public int FindIndex()
2226
{
2327
if (_index > -1)
2428
return _index;
25-
var siblings = Parent!.OfType<TabSetBlock>().ToList();
26-
_index = siblings.IndexOf(this);
29+
30+
_index = Line;
2731
return _index;
2832
}
2933
}
34+
3035
public class TabItemBlock(DirectiveBlockParser parser, ParserContext context)
3136
: DirectiveBlock(parser, context)
3237
{
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
@inherits RazorSlice<TabItemViewModel>
2-
<input class="tabs-input" checked="@(Model.Index == 0 ? "checked" : "")" id="[email protected]@Model.Index" name="[email protected]" type="radio" tabindex="0">
3-
<label class="tabs-label" data-sync-id="@Model.SyncKey" data-sync-group="@Model.TabSetGroupKey" for="[email protected]@Model.Index">@Model.Title</label>
2+
3+
@{
4+
var id = $"tabs-item-{Model.TabSetIndex}-{Model.Index}";
5+
}
6+
7+
<input class="tabs-input" checked="@(Model.Index == 0 ? "checked" : "")" id="@id" name="[email protected]" type="radio" tabindex="0">
8+
<label class="tabs-label" data-sync-id="@Model.SyncKey" data-sync-group="@Model.TabSetGroupKey" for="@id">@Model.Title</label>
49
<div class="tabs-content" tabindex="0">
510
[CONTENT]
611
</div>

tests/Elastic.Markdown.Tests/Directives/TabTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public void ParsesTabItems()
4949
for (var i = 0; i < items.Length; i++)
5050
{
5151
items[i].Index.Should().Be(i);
52-
items[i].TabSetIndex.Should().Be(0);
5352
}
5453
}
5554
}
@@ -88,7 +87,7 @@ public void ParsesMultipleTabSets()
8887
for (var i = 0; i < items.Length; i++)
8988
{
9089
items[i].Index.Should().Be(i);
91-
items[i].TabSetIndex.Should().Be(s);
90+
items[i].TabSetIndex.Should().Be(sets[s].Line);
9291
}
9392
}
9493
}
@@ -148,7 +147,7 @@ public void ParsesMultipleTabSets()
148147
for (var i = 0; i < items.Length; i++)
149148
{
150149
items[i].Index.Should().Be(i);
151-
items[i].TabSetIndex.Should().Be(s);
150+
items[i].TabSetIndex.Should().Be(sets[s].Line);
152151
}
153152
}
154153
}

0 commit comments

Comments
 (0)