Skip to content

Commit 23ffff5

Browse files
committed
Fix tabs in list
1 parent 65f92a0 commit 23ffff5

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
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: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5+
using System.Reflection.Metadata;
56
using Elastic.Markdown.Diagnostics;
67
using Elastic.Markdown.Helpers;
8+
using Markdig.Syntax;
9+
using System.Linq;
710

811
namespace Elastic.Markdown.Myst.Directives;
912

1013
public class TabSetBlock(DirectiveBlockParser parser, ParserContext context)
1114
: DirectiveBlock(parser, context)
1215
{
16+
public string Id { get; private set; } = Guid.NewGuid().ToString();
17+
1318
public override string Directive => "tab-set";
1419

1520
public int Index { get; set; }
@@ -18,15 +23,20 @@ public class TabSetBlock(DirectiveBlockParser parser, ParserContext context)
1823
public override void FinalizeAndValidate(ParserContext context) => Index = FindIndex();
1924

2025
private int _index = -1;
26+
27+
// For simplicity, we use the line number as the index.
28+
// It's not ideal, but it's unique.
29+
// This is more efficient than finding the root block and then finding the index.
2130
public int FindIndex()
2231
{
2332
if (_index > -1)
2433
return _index;
25-
var siblings = Parent!.OfType<TabSetBlock>().ToList();
26-
_index = siblings.IndexOf(this);
34+
35+
_index = Line;
2736
return _index;
2837
}
2938
}
39+
3040
public class TabItemBlock(DirectiveBlockParser parser, ParserContext context)
3141
: DirectiveBlock(parser, context)
3242
{
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>

0 commit comments

Comments
 (0)