Skip to content

Commit 57d6cfd

Browse files
authored
Revert "Add PrimaryNav feature (#604)" (#635)
This reverts commit 8edd22a.
1 parent 8edd22a commit 57d6cfd

36 files changed

+158
-657
lines changed

docs/_docset.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ subs:
99
serverless-short: Serverless
1010
ece: "Elastic Cloud Enterprise"
1111
eck: "Elastic Cloud on Kubernetes"
12-
13-
features:
14-
primary-nav: false
15-
1612
toc:
1713
- file: index.md
1814
- hidden: developer-notes.md

src/Elastic.Markdown/Assets/pages-nav.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ function scrollCurrentNaviItemIntoView(nav: HTMLElement, delay: number) {
1515
const currentNavItem = $('.current', nav);
1616
expandAllParents(currentNavItem);
1717
setTimeout(() => {
18+
1819
if (currentNavItem && !isElementInViewport(currentNavItem)) {
1920
currentNavItem.scrollIntoView({ behavior: 'smooth', block: 'center' });
20-
window.scrollTo(0, 0);
2121
}
2222
}, delay);
2323
}
@@ -36,7 +36,7 @@ export function initNav() {
3636
if (!pagesNav) {
3737
return;
3838
}
39-
const navItems = $$('a[href="' + window.location.pathname + '"], a[href="' + window.location.pathname + '/"]', pagesNav);
39+
const navItems = $$('a[href="' + window.location.pathname + '"]', pagesNav);
4040
navItems.forEach(el => {
4141
el.classList.add('current');
4242
});

src/Elastic.Markdown/Assets/styles.css

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,16 @@
7272

7373
.sidebar {
7474
.sidebar-nav {
75-
@apply sticky top-21 z-30 overflow-y-auto;
75+
@apply sticky top-22 z-30 overflow-y-auto;
7676
max-height: calc(100vh - var(--spacing) * 22);
77-
scrollbar-gutter: stable;
7877
}
7978

8079
.sidebar-link {
8180
@apply
8281
text-ink-light
8382
hover:text-black
8483
text-sm
85-
text-wrap
86-
inline-block
87-
leading-[1.3em]
84+
leading-[1.2em]
8885
tracking-[-0.02em];
8986
}
9087
}
@@ -172,7 +169,7 @@
172169
}
173170

174171
#pages-nav .current {
175-
@apply font-semibold text-blue-elastic!;
172+
@apply text-blue-elastic!;
176173
}
177174

178175
.markdown-content {

src/Elastic.Markdown/Helpers/Htmx.cs

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,9 @@
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.Text;
6-
using Elastic.Markdown.IO.Configuration;
7-
85
namespace Elastic.Markdown.Helpers;
96

10-
public static class Htmx
7+
public class Htmx
118
{
12-
public static string GetHxSelectOob(FeatureFlags features, string? pathPrefix, string currentUrl, string targetUrl)
13-
{
14-
HashSet<string> selectTargets =
15-
[
16-
"#primary-nav", "#secondary-nav", "#markdown-content", "#toc-nav", "#prev-next-nav", "#breadcrumbs"
17-
];
18-
if (!HasSameTopLevelGroup(pathPrefix, currentUrl, targetUrl) && features.IsPrimaryNavEnabled)
19-
_ = selectTargets.Add("#pages-nav");
20-
return string.Join(',', selectTargets);
21-
}
22-
23-
public static bool HasSameTopLevelGroup(string? pathPrefix, string currentUrl, string targetUrl)
24-
{
25-
var startIndex = pathPrefix?.Length ?? 0;
26-
var currentSegments = GetSegments(currentUrl[startIndex..].Trim('/'));
27-
var targetSegments = GetSegments(targetUrl[startIndex..].Trim('/'));
28-
return currentSegments.Length >= 1 && targetSegments.Length >= 1 && currentSegments[0] == targetSegments[0];
29-
}
30-
31-
public static string GetPreload() => "true";
32-
33-
public static string GetHxSwap() => "none";
34-
public static string GetHxPushUrl() => "true";
35-
public static string GetHxIndicator() => "#htmx-indicator";
36-
37-
private static string[] GetSegments(string url) => url.Split('/');
38-
39-
public static string GetHxAttributes(FeatureFlags features, string? pathPrefix, string currentUrl, string targetUrl)
40-
{
41-
42-
var attributes = new StringBuilder();
43-
_ = attributes.Append($" hx-get={targetUrl}");
44-
_ = attributes.Append($" hx-select-oob={GetHxSelectOob(features, pathPrefix, currentUrl, targetUrl)}");
45-
_ = attributes.Append($" hx-swap={GetHxSwap()}");
46-
_ = attributes.Append($" hx-push-url={GetHxPushUrl()}");
47-
_ = attributes.Append($" hx-indicator={GetHxIndicator()}");
48-
_ = attributes.Append($" preload={GetPreload()}");
49-
return attributes.ToString();
50-
}
9+
public static string GetHxSelectOob() => "#markdown-content,#toc-nav,#prev-next-nav,#breadcrumbs";
5110
}

src/Elastic.Markdown/IO/Configuration/ConfigurationFile.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ public record ConfigurationFile : DocumentationFile
3131
private readonly Dictionary<string, string> _substitutions = new(StringComparer.OrdinalIgnoreCase);
3232
public IReadOnlyDictionary<string, string> Substitutions => _substitutions;
3333

34-
private readonly Dictionary<string, bool> _features = new(StringComparer.OrdinalIgnoreCase);
35-
private FeatureFlags? _featureFlags;
36-
public FeatureFlags Features => _featureFlags ??= new FeatureFlags(_features);
37-
3834
public ConfigurationFile(IFileInfo sourceFile, IDirectoryInfo rootPath, BuildContext context, int depth = 0, string parentPath = "")
3935
: base(sourceFile, rootPath)
4036
{
@@ -83,9 +79,6 @@ public ConfigurationFile(IFileInfo sourceFile, IDirectoryInfo rootPath, BuildCon
8379

8480
TableOfContents = entries;
8581
break;
86-
case "features":
87-
_features = reader.ReadDictionary(entry.Entry).ToDictionary(k => k.Key, v => bool.Parse(v.Value), StringComparer.OrdinalIgnoreCase);
88-
break;
8982
case "external_hosts":
9083
reader.EmitWarning($"{entry.Key} has been deprecated and will be removed", entry.Key);
9184
break;
@@ -104,8 +97,6 @@ public ConfigurationFile(IFileInfo sourceFile, IDirectoryInfo rootPath, BuildCon
10497
Globs = [.. ImplicitFolders.Select(f => Glob.Parse($"{f}/*.md"))];
10598
}
10699

107-
public bool IsFeatureEnabled(string feature) => _features.TryGetValue(feature, out var enabled) && enabled;
108-
109100
private List<ITocItem> ReadChildren(YamlStreamReader reader, KeyValuePair<YamlNode, YamlNode> entry, string parentPath)
110101
{
111102
var entries = new List<ITocItem>();

src/Elastic.Markdown/IO/Configuration/FeatureFlags.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Elastic.Markdown/IO/MarkdownFile.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -316,21 +316,12 @@ private YamlFrontMatter ReadYamlFrontMatter(string raw)
316316
}
317317

318318

319-
public string CreateHtml(MarkdownDocument document)
319+
public static string CreateHtml(MarkdownDocument document)
320320
{
321321
//we manually render title and optionally append an applies block embedded in yaml front matter.
322322
var h1 = document.Descendants<HeadingBlock>().FirstOrDefault(h => h.Level == 1);
323323
if (h1 is not null)
324324
_ = document.Remove(h1);
325325
return document.ToHtml(MarkdownParser.Pipeline);
326326
}
327-
328-
public static string CreateHtml(MarkdownDocument document, MarkdownParser parser)
329-
{
330-
//we manually render title and optionally append an applies block embedded in yaml front matter.
331-
var h1 = document.Descendants<HeadingBlock>().FirstOrDefault(h => h.Level == 1);
332-
if (h1 is not null)
333-
_ = document.Remove(h1);
334-
return document.ToHtml(parser.Pipeline);
335-
}
336327
}

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace Elastic.Markdown.Myst.Directives;
2121
/// An HTML renderer for a <see cref="DirectiveBlock"/>.
2222
/// </summary>
2323
/// <seealso cref="HtmlObjectRenderer{CustomContainer}" />
24-
public class DirectiveHtmlRenderer(MarkdownParser markdownParser) : HtmlObjectRenderer<DirectiveBlock>
24+
public class DirectiveHtmlRenderer : HtmlObjectRenderer<DirectiveBlock>
2525
{
2626
protected override void Write(HtmlRenderer renderer, DirectiveBlock directiveBlock)
2727
{
@@ -62,10 +62,10 @@ protected override void Write(HtmlRenderer renderer, DirectiveBlock directiveBlo
6262
if (includeBlock.Literal)
6363
WriteLiteralIncludeBlock(renderer, includeBlock);
6464
else
65-
WriteIncludeBlock(renderer, includeBlock, markdownParser);
65+
WriteIncludeBlock(renderer, includeBlock);
6666
return;
6767
case SettingsBlock settingsBlock:
68-
WriteSettingsBlock(renderer, settingsBlock, markdownParser);
68+
WriteSettingsBlock(renderer, settingsBlock);
6969
return;
7070
default:
7171
// if (!string.IsNullOrEmpty(directiveBlock.Info) && !directiveBlock.Info.StartsWith('{'))
@@ -219,24 +219,28 @@ private static void WriteLiteralIncludeBlock(HtmlRenderer renderer, IncludeBlock
219219
}
220220
}
221221

222-
private static void WriteIncludeBlock(HtmlRenderer renderer, IncludeBlock block, MarkdownParser parser)
222+
private static void WriteIncludeBlock(HtmlRenderer renderer, IncludeBlock block)
223223
{
224224
if (!block.Found || block.IncludePath is null)
225225
return;
226226

227+
var parser = new MarkdownParser(block.Build, block.Context);
227228
var snippet = block.Build.ReadFileSystem.FileInfo.New(block.IncludePath);
228229
var parentPath = block.Context.MarkdownSourcePath;
229230
var document = parser.ParseSnippetAsync(snippet, parentPath, block.Context.YamlFrontMatter, default).GetAwaiter().GetResult();
230-
var html = document.ToHtml(parser.Pipeline);
231+
var html = document.ToHtml(MarkdownParser.Pipeline);
231232
_ = renderer.Write(html);
232233
}
233234

234-
private static void WriteSettingsBlock(HtmlRenderer renderer, SettingsBlock block, MarkdownParser parser)
235+
private static void WriteSettingsBlock(HtmlRenderer renderer, SettingsBlock block)
235236
{
236237
if (!block.Found || block.IncludePath is null)
237238
return;
238239

240+
var parser = new MarkdownParser(block.Build, block.Context);
241+
239242
var file = block.Build.ReadFileSystem.FileInfo.New(block.IncludePath);
243+
240244
YamlSettings? settings;
241245
try
242246
{
@@ -260,7 +264,7 @@ private static void WriteSettingsBlock(HtmlRenderer renderer, SettingsBlock bloc
260264
RenderMarkdown = s =>
261265
{
262266
var document = parser.ParseEmbeddedMarkdown(s, block.IncludeFrom, block.Context.YamlFrontMatter);
263-
var html = document.ToHtml(parser.Pipeline);
267+
var html = document.ToHtml(MarkdownParser.Pipeline);
264268
return html;
265269
}
266270
});

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ namespace Elastic.Markdown.Myst.Directives;
1313

1414
public static class DirectiveMarkdownBuilderExtensions
1515
{
16-
public static MarkdownPipelineBuilder UseDirectives(this MarkdownPipelineBuilder pipeline, MarkdownParser markdownParser)
16+
public static MarkdownPipelineBuilder UseDirectives(this MarkdownPipelineBuilder pipeline)
1717
{
18-
pipeline.Extensions.AddIfNotAlready(new DirectiveMarkdownExtension(markdownParser));
18+
pipeline.Extensions.AddIfNotAlready<DirectiveMarkdownExtension>();
1919
return pipeline;
2020
}
2121
}
@@ -24,7 +24,7 @@ public static MarkdownPipelineBuilder UseDirectives(this MarkdownPipelineBuilder
2424
/// Extension to allow custom containers.
2525
/// </summary>
2626
/// <seealso cref="IMarkdownExtension" />
27-
public class DirectiveMarkdownExtension(MarkdownParser markdownParser) : IMarkdownExtension
27+
public class DirectiveMarkdownExtension : IMarkdownExtension
2828
{
2929
public void Setup(MarkdownPipelineBuilder pipeline)
3030
{
@@ -53,7 +53,7 @@ public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer)
5353
if (!renderer.ObjectRenderers.Contains<DirectiveHtmlRenderer>())
5454
{
5555
// Must be inserted before CodeBlockRenderer
56-
_ = renderer.ObjectRenderers.InsertBefore<CodeBlockRenderer>(new DirectiveHtmlRenderer(markdownParser));
56+
_ = renderer.ObjectRenderers.InsertBefore<CodeBlockRenderer>(new DirectiveHtmlRenderer());
5757
}
5858

5959
_ = renderer.ObjectRenderers.Replace<HeadingRenderer>(new SectionedHeadingRenderer());

src/Elastic.Markdown/Myst/MarkdownParser.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
using System.IO.Abstractions;
66
using Cysharp.IO;
7-
using Elastic.Markdown.IO.Configuration;
87
using Elastic.Markdown.Myst.CodeBlocks;
98
using Elastic.Markdown.Myst.Comments;
109
using Elastic.Markdown.Myst.Directives;
@@ -102,33 +101,33 @@ private static async Task<MarkdownDocument> ParseAsync(
102101
}
103102

104103
// ReSharper disable once InconsistentNaming
105-
private MarkdownPipeline? _minimalPipelineCached;
106-
private MarkdownPipeline MinimalPipeline
104+
private static MarkdownPipeline? MinimalPipelineCached;
105+
private static MarkdownPipeline MinimalPipeline
107106
{
108107
get
109108
{
110-
if (_minimalPipelineCached is not null)
111-
return _minimalPipelineCached;
109+
if (MinimalPipelineCached is not null)
110+
return MinimalPipelineCached;
112111
var builder = new MarkdownPipelineBuilder()
113112
.UseYamlFrontMatter()
114113
.UseInlineAnchors()
115114
.UseHeadingsWithSlugs()
116-
.UseDirectives(this);
115+
.UseDirectives();
117116

118117
_ = builder.BlockParsers.TryRemove<IndentedCodeBlockParser>();
119-
_minimalPipelineCached = builder.Build();
120-
return _minimalPipelineCached;
118+
MinimalPipelineCached = builder.Build();
119+
return MinimalPipelineCached;
121120
}
122121
}
123122

124123
// ReSharper disable once InconsistentNaming
125-
private MarkdownPipeline? _pipelineCached;
126-
public MarkdownPipeline Pipeline
124+
private static MarkdownPipeline? PipelineCached;
125+
public static MarkdownPipeline Pipeline
127126
{
128127
get
129128
{
130-
if (_pipelineCached is not null)
131-
return _pipelineCached;
129+
if (PipelineCached is not null)
130+
return PipelineCached;
132131

133132
var builder = new MarkdownPipelineBuilder()
134133
.UseInlineAnchors()
@@ -142,15 +141,15 @@ public MarkdownPipeline Pipeline
142141
.UseYamlFrontMatter()
143142
.UseGridTables()
144143
.UsePipeTables()
145-
.UseDirectives(this)
144+
.UseDirectives()
146145
.UseDefinitionLists()
147146
.UseEnhancedCodeBlocks()
148-
.UseHtmxLinkInlineRenderer(Build)
147+
.UseHtmxLinkInlineRenderer()
149148
.DisableHtml()
150149
.UseHardBreaks();
151150
_ = builder.BlockParsers.TryRemove<IndentedCodeBlockParser>();
152-
_pipelineCached = builder.Build();
153-
return _pipelineCached;
151+
PipelineCached = builder.Build();
152+
return PipelineCached;
154153
}
155154
}
156155

0 commit comments

Comments
 (0)