From 23ffff581d652e636c955f8763f0a2e3e9ca98da Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Fri, 21 Feb 2025 19:18:16 +0100 Subject: [PATCH 1/5] Fix tabs in list --- src/Elastic.Markdown/Assets/markdown/list.css | 9 ++++++--- .../Myst/Directives/TabSetBlock.cs | 14 ++++++++++++-- .../Slices/Directives/TabItem.cshtml | 9 +++++++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/Elastic.Markdown/Assets/markdown/list.css b/src/Elastic.Markdown/Assets/markdown/list.css index 6a04a9cad..52e10897e 100644 --- a/src/Elastic.Markdown/Assets/markdown/list.css +++ b/src/Elastic.Markdown/Assets/markdown/list.css @@ -37,10 +37,13 @@ ol>li>ol>li>ol>li>ol>li>ol>li>ol { list-style-type: lower-roman; } /* Special handling of elements within a list item */ - li>p:nth-child(2), - li>div>.highlight, - li>.admonition + li>*:first-child, + li>p:nth-child(2) { @apply mt-1; } + li>p:first-child + { + @apply mt-4; + } } diff --git a/src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs b/src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs index ee88b05d8..ca8e51472 100644 --- a/src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs +++ b/src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs @@ -2,14 +2,19 @@ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information +using System.Reflection.Metadata; using Elastic.Markdown.Diagnostics; using Elastic.Markdown.Helpers; +using Markdig.Syntax; +using System.Linq; namespace Elastic.Markdown.Myst.Directives; public class TabSetBlock(DirectiveBlockParser parser, ParserContext context) : DirectiveBlock(parser, context) { + public string Id { get; private set; } = Guid.NewGuid().ToString(); + public override string Directive => "tab-set"; public int Index { get; set; } @@ -18,15 +23,20 @@ public class TabSetBlock(DirectiveBlockParser parser, ParserContext context) public override void FinalizeAndValidate(ParserContext context) => Index = FindIndex(); private int _index = -1; + + // For simplicity, we use the line number as the index. + // It's not ideal, but it's unique. + // This is more efficient than finding the root block and then finding the index. public int FindIndex() { if (_index > -1) return _index; - var siblings = Parent!.OfType().ToList(); - _index = siblings.IndexOf(this); + + _index = Line; return _index; } } + public class TabItemBlock(DirectiveBlockParser parser, ParserContext context) : DirectiveBlock(parser, context) { diff --git a/src/Elastic.Markdown/Slices/Directives/TabItem.cshtml b/src/Elastic.Markdown/Slices/Directives/TabItem.cshtml index b11cd161b..d6facc90c 100644 --- a/src/Elastic.Markdown/Slices/Directives/TabItem.cshtml +++ b/src/Elastic.Markdown/Slices/Directives/TabItem.cshtml @@ -1,6 +1,11 @@ @inherits RazorSlice - - + +@{ + var id = $"tabs-item-{Model.TabSetIndex}-{Model.Index}"; +} + + +
[CONTENT]
From a7bbd0f81c30302a458aa37be80c44c5c2d345af Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Fri, 21 Feb 2025 19:25:09 +0100 Subject: [PATCH 2/5] format --- src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs b/src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs index ca8e51472..1058ae5d4 100644 --- a/src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs +++ b/src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs @@ -2,11 +2,11 @@ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information +using System.Linq; using System.Reflection.Metadata; using Elastic.Markdown.Diagnostics; using Elastic.Markdown.Helpers; using Markdig.Syntax; -using System.Linq; namespace Elastic.Markdown.Myst.Directives; From 3754104e36c16e2eb6c525bf7e0653e4215b5d7c Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Fri, 21 Feb 2025 19:58:36 +0100 Subject: [PATCH 3/5] Fix tests --- tests/Elastic.Markdown.Tests/Directives/TabTests.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/Elastic.Markdown.Tests/Directives/TabTests.cs b/tests/Elastic.Markdown.Tests/Directives/TabTests.cs index 3153e4c78..05fb0732b 100644 --- a/tests/Elastic.Markdown.Tests/Directives/TabTests.cs +++ b/tests/Elastic.Markdown.Tests/Directives/TabTests.cs @@ -49,7 +49,6 @@ public void ParsesTabItems() for (var i = 0; i < items.Length; i++) { items[i].Index.Should().Be(i); - items[i].TabSetIndex.Should().Be(0); } } } @@ -88,7 +87,7 @@ public void ParsesMultipleTabSets() for (var i = 0; i < items.Length; i++) { items[i].Index.Should().Be(i); - items[i].TabSetIndex.Should().Be(s); + items[i].TabSetIndex.Should().Be(sets[s].Line); } } } @@ -148,7 +147,7 @@ public void ParsesMultipleTabSets() for (var i = 0; i < items.Length; i++) { items[i].Index.Should().Be(i); - items[i].TabSetIndex.Should().Be(s); + items[i].TabSetIndex.Should().Be(sets[s].Line); } } } From 0e5fca8d9a66dbb5ad39c4ed7e3f495868e596b4 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Fri, 21 Feb 2025 23:18:37 +0100 Subject: [PATCH 4/5] Remove unused imports --- src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs b/src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs index 1058ae5d4..95540c367 100644 --- a/src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs +++ b/src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs @@ -2,11 +2,8 @@ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information -using System.Linq; -using System.Reflection.Metadata; using Elastic.Markdown.Diagnostics; using Elastic.Markdown.Helpers; -using Markdig.Syntax; namespace Elastic.Markdown.Myst.Directives; From 3f3311eab3b851fa25164e894ee804bac29154d0 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Sat, 22 Feb 2025 10:55:53 +0100 Subject: [PATCH 5/5] Update src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs --- src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs b/src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs index 95540c367..fc4372e34 100644 --- a/src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs +++ b/src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs @@ -10,8 +10,6 @@ namespace Elastic.Markdown.Myst.Directives; public class TabSetBlock(DirectiveBlockParser parser, ParserContext context) : DirectiveBlock(parser, context) { - public string Id { get; private set; } = Guid.NewGuid().ToString(); - public override string Directive => "tab-set"; public int Index { get; set; }