Skip to content

Commit

Permalink
Remove implemented directives that are not needed (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz authored Nov 12, 2024
1 parent 53fd0b2 commit fbc97be
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 348 deletions.
25 changes: 0 additions & 25 deletions src/Elastic.Markdown/Myst/Directives/CardBlock.cs

This file was deleted.

35 changes: 18 additions & 17 deletions src/Elastic.Markdown/Myst/Directives/DirectiveBlockParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ public DirectiveBlockParser()
{ "exercise", 30 },
{ "solution", 31 },
{ "toctree", 32 },
{ "grid", 26 },
{ "grid-item-card", 26 },
{ "card", 25 },
{ "mermaid", 20 },
{ "aside", 4 },
{ "margin", 4 },
{ "sidebar", 4 },
{ "code-cell", 8 },


}.ToFrozenDictionary();

protected override DirectiveBlock CreateFencedBlock(BlockProcessor processor)
Expand All @@ -67,24 +77,17 @@ protected override DirectiveBlock CreateFencedBlock(BlockProcessor processor)
if (info.IndexOf("{") == -1)
return new CodeBlock(this, "raw", _admonitionData);

// TODO alternate lookup .NET 9
var directive = info.ToString().Trim(['{', '}', '`']);
if (_unsupportedBlocks.TryGetValue(directive, out var issueId))
return new UnsupportedDirectiveBlock(this, directive, _admonitionData, issueId);

if (info.IndexOf("{tab-set}") > 0)
return new TabSetBlock(this, _admonitionData);

if (info.IndexOf("{tab-item}") > 0)
return new TabItemBlock(this, _admonitionData);

if (info.IndexOf("{sidebar}") > 0)
return new SideBarBlock(this, _admonitionData);

if (info.IndexOf("{card}") > 0)
return new CardBlock(this, _admonitionData);

if (info.IndexOf("{grid}") > 0)
return new GridBlock(this, _admonitionData);

if (info.IndexOf("{grid-item-card}") > 0)
return new GridItemCardBlock(this, _admonitionData);

if (info.IndexOf("{dropdown}") > 0)
return new DropdownBlock(this, _admonitionData);

Expand All @@ -97,6 +100,9 @@ protected override DirectiveBlock CreateFencedBlock(BlockProcessor processor)
if (info.IndexOf("{figure-md}") > 0)
return new FigureBlock(this, _admonitionData, context);

// this is currently listed as unsupported
// leaving the parsing in untill we are confident we don't want this
// for dev-docs
if (info.IndexOf("{mermaid}") > 0)
return new MermaidBlock(this, _admonitionData);

Expand All @@ -123,11 +129,6 @@ protected override DirectiveBlock CreateFencedBlock(BlockProcessor processor)
if (info.IndexOf($"{{{code}}}") > 0)
return new CodeBlock(this, code, _admonitionData);
}
// TODO alternate lookup .NET 9
var directive = info.ToString().Trim(['{', '}', '`']);
if (_unsupportedBlocks.TryGetValue(directive, out var issueId))
return new UnsupportedDirectiveBlock(this, directive, _admonitionData, issueId);

return new UnknownDirectiveBlock(this, info.ToString(), _admonitionData);
}

Expand Down
42 changes: 0 additions & 42 deletions src/Elastic.Markdown/Myst/Directives/DirectiveHtmlRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,12 @@ protected override void Write(HtmlRenderer renderer, DirectiveBlock directiveBlo
case CodeBlock codeBlock:
WriteCode(renderer, codeBlock);
return;
case SideBarBlock sideBar:
WriteSideBar(renderer, sideBar);
return;
case TabSetBlock tabSet:
WriteTabSet(renderer, tabSet);
return;
case TabItemBlock tabItem:
WriteTabItem(renderer, tabItem);
return;
case CardBlock card:
WriteCard(renderer, card);
return;
case GridBlock grid:
WriteGrid(renderer, grid);
return;
case GridItemCardBlock gridItemCard:
WriteGridItemCard(renderer, gridItemCard);
return;
case LiteralIncludeBlock literalIncludeBlock:
WriteLiteralIncludeBlock(renderer, literalIncludeBlock);
return;
Expand Down Expand Up @@ -135,30 +123,6 @@ private void WriteFigure(HtmlRenderer renderer, ImageBlock block)
private void WriteChildren(HtmlRenderer renderer, DirectiveBlock directiveBlock) =>
renderer.WriteChildren(directiveBlock);

private void WriteCard(HtmlRenderer renderer, CardBlock block)
{
var slice = Card.Create(new CardViewModel { Title = block.Title, Link = block.Link });
RenderRazorSlice(slice, renderer, block);
}

private void WriteGrid(HtmlRenderer renderer, GridBlock block)
{
var slice = Grid.Create(new GridViewModel
{
BreakPoint = block.BreakPoint
});
RenderRazorSlice(slice, renderer, block);
}

private void WriteGridItemCard(HtmlRenderer renderer, GridItemCardBlock directiveBlock)
{
var title = directiveBlock.Arguments;
var link = directiveBlock.Properties.GetValueOrDefault("link");
var slice = GridItemCard.Create(new GridItemCardViewModel { Title = title, Link = link });
RenderRazorSlice(slice, renderer, directiveBlock);
}


private void WriteVersion(HtmlRenderer renderer, VersionBlock block)
{
var slice = Slices.Directives.Version.Create(new VersionViewModel
Expand Down Expand Up @@ -204,12 +168,6 @@ private void WriteCode(HtmlRenderer renderer, CodeBlock block)
}


private void WriteSideBar(HtmlRenderer renderer, SideBarBlock directiveBlock)
{
var slice = SideBar.Create(new SideBarViewModel());
RenderRazorSlice(slice, renderer, directiveBlock);
}

private void WriteTabSet(HtmlRenderer renderer, TabSetBlock block)
{
var slice = TabSet.Create(new TabSetViewModel());
Expand Down
12 changes: 0 additions & 12 deletions src/Elastic.Markdown/Myst/Directives/SideBarBlock.cs

This file was deleted.

92 changes: 0 additions & 92 deletions src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,95 +36,3 @@ public override void FinalizeAndValidate(ParserContext context)
}

}

public class GridResponsive
{
public required int Xs { get; init; }
public required int Sm { get; init; }
public required int Md { get; init; }
public required int Lg { get; init; }
}
public class GridCorners
{
public required int Top { get; init; }
public required int Bottom { get; init; }
public required int Left { get; init; }
public required int Right { get; init; }
}

public class GridBlock(DirectiveBlockParser parser, Dictionary<string, string> properties)
: DirectiveBlock(parser, properties)
{

public GridResponsive BreakPoint { get; set; } = new() { Xs = 1, Sm = 1, Md = 2, Lg = 3 };

/// <summary> Spacing between items. One or four integers (for “xs sm md lg”) between 0 and 5. </summary>
public GridResponsive? Gutter { get; set; }

/// <summary> Outer margin of grid. One (all) or four (top bottom left right) values from: 0, 1, 2, 3, 4, 5, auto. </summary>
public GridCorners? Margin { get; set; }

/// <summary> Inner padding of grid. One (all) or four (top bottom left right) values from: 0, 1, 2, 3, 4, 5. </summary>
public GridCorners? Padding { get; set; }

/// <summary> Create a border around the grid. </summary>
public bool? Outline { get; set; }

/// <summary> Reverse the order of the grid items. </summary>
public bool? Reverse { get; set; }

/// <summary> Additional CSS classes for the grid container element. </summary>
public string? ClassContainer { get; set; }

/// <summary> Additional CSS classes for the grid row element </summary>
public string? ClassRow { get; set; }


public override void FinalizeAndValidate(ParserContext context)
{
//todo we always assume 4 integers
if (!string.IsNullOrEmpty(Arguments))
ParseData(Arguments, (xs, sm, md, lg) => BreakPoint = new() { Xs = xs, Sm = sm, Md = md, Lg = lg });
else
{
//todo invalidate
}
if (Properties.GetValueOrDefault("gutter") is { } gutter)
ParseData(gutter, (xs, sm, md, lg) => Gutter = new() { Xs = xs, Sm = sm, Md = md, Lg = lg });
if (Properties.GetValueOrDefault("margin") is { } margin)
ParseData(margin, (top, bottom, left, right) => Margin = new() { Top = top, Bottom = bottom, Left = left, Right = right });
if (Properties.GetValueOrDefault("padding") is { } padding)
ParseData(padding, (top, bottom, left, right) => Padding = new() { Top = top, Bottom = bottom, Left = left, Right = right });
ParseBool("outline", b => Outline = b);
ParseBool("reverse", b => Reverse = b);

ClassContainer = Properties.GetValueOrDefault("class-container");
ClassRow = Properties.GetValueOrDefault("class-row");

}

private void ParseData(string data, Action<int, int, int, int> setter, bool allowAuto = true)
{
var columns = data.Split(' ')
.Select(t => int.TryParse(t, out var c) ? c : t == "auto" ? -1 : -2)
.Where(t => t is > -2 and <= 5)
.ToArray();
if (columns.Length == 1)
setter(columns[0], columns[0], columns[0], columns[0]);
else if (columns.Length == 4)
setter(columns[0], columns[1], columns[2], columns[3]);
else
{
//todo invalidate
}
}


}
public class GridItemCardBlock(DirectiveBlockParser parser, Dictionary<string, string> properties)
: DirectiveBlock(parser, properties)
{
public override void FinalizeAndValidate(ParserContext context)
{
}
}
11 changes: 0 additions & 11 deletions src/Elastic.Markdown/Slices/Directives/Card.cshtml

This file was deleted.

10 changes: 0 additions & 10 deletions src/Elastic.Markdown/Slices/Directives/Grid.cshtml

This file was deleted.

13 changes: 0 additions & 13 deletions src/Elastic.Markdown/Slices/Directives/GridItemCard.cshtml

This file was deleted.

4 changes: 0 additions & 4 deletions src/Elastic.Markdown/Slices/Directives/SideBar.cshtml

This file was deleted.

18 changes: 0 additions & 18 deletions src/Elastic.Markdown/Slices/Directives/_ViewModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class VersionViewModel
public required string Title { get; init; }
}

public class SideBarViewModel;
public class TabSetViewModel;

public class TabItemViewModel
Expand All @@ -39,23 +38,6 @@ public class TabItemViewModel
public required string Title { get; init; }
}

public class CardViewModel
{
public required string? Title { get; init; }
public required string? Link { get; init; }
}

public class GridViewModel
{
public required GridResponsive BreakPoint { get; init; }
}

public class GridItemCardViewModel
{
public required string? Title { get; init; }
public required string? Link { get; init; }
}

public class IncludeViewModel
{
public required string Html { get; init; }
Expand Down
39 changes: 0 additions & 39 deletions tests/Elastic.Markdown.Tests/Directives/CardTests.cs

This file was deleted.

Loading

0 comments on commit fbc97be

Please sign in to comment.