From f5fc018989ff9ff7b25a879a774bcfbfadb3afcb Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Thu, 14 Nov 2024 09:54:27 +0100 Subject: [PATCH] Finish tab and tab-item (#66) --- .../Myst/Directives/TabSetBlock.cs | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs b/src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs index 0dceaf5..b5dbe9c 100644 --- a/src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs +++ b/src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs @@ -1,8 +1,6 @@ // Licensed to Elasticsearch B.V under one or more agreements. // 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.Xml; -using System.Xml.Xsl; namespace Elastic.Markdown.Myst.Directives; @@ -26,17 +24,26 @@ public int FindIndex() public class TabItemBlock(DirectiveBlockParser parser, Dictionary properties) : DirectiveBlock(parser, properties) { - public override string Directive => "tab-set-item"; + public override string Directive => "tab-item"; - public string Title { get; set; } = default!; - public int Index { get; set; } - public int TabSetIndex { get; set; } + public string Title { get; private set; } = default!; + public int Index { get; private set; } + public int TabSetIndex { get; private set; } + + public string? SyncKey { get; private set; } + public bool Selected { get; private set; } public override void FinalizeAndValidate(ParserContext context) { - Title = Arguments ?? "Unnamed Tab"; + if (string.IsNullOrWhiteSpace(Arguments)) + EmitError(context, "{tab-item} requires an argument to name the tab."); + + Title = Arguments ?? "{undefined}"; Index = Parent!.IndexOf(this); TabSetIndex = Parent is TabSetBlock tb ? tb.FindIndex() : -1; + + SyncKey = Prop("sync"); + Selected = PropBool("selected"); } }