Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions docs/_docset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ subs:
serverless-short: Serverless
ece: "Elastic Cloud Enterprise"
eck: "Elastic Cloud on Kubernetes"

features:
primary-nav: false

toc:
- file: index.md
- hidden: developer-notes.md
Expand Down
4 changes: 2 additions & 2 deletions src/Elastic.Markdown/Assets/pages-nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ function scrollCurrentNaviItemIntoView(nav: HTMLElement, delay: number) {
const currentNavItem = $('.current', nav);
expandAllParents(currentNavItem);
setTimeout(() => {

if (currentNavItem && !isElementInViewport(currentNavItem)) {
currentNavItem.scrollIntoView({ behavior: 'smooth', block: 'center' });
window.scrollTo(0, 0);
}
}, delay);
}
Expand All @@ -36,7 +36,7 @@ export function initNav() {
if (!pagesNav) {
return;
}
const navItems = $$('a[href="' + window.location.pathname + '"], a[href="' + window.location.pathname + '/"]', pagesNav);
const navItems = $$('a[href="' + window.location.pathname + '"]', pagesNav);
navItems.forEach(el => {
el.classList.add('current');
});
Expand Down
9 changes: 3 additions & 6 deletions src/Elastic.Markdown/Assets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,16 @@

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

.sidebar-link {
@apply
text-ink-light
hover:text-black
text-sm
text-wrap
inline-block
leading-[1.3em]
leading-[1.2em]
tracking-[-0.02em];
}
}
Expand Down Expand Up @@ -172,7 +169,7 @@
}

#pages-nav .current {
@apply font-semibold text-blue-elastic!;
@apply text-blue-elastic!;
}

.markdown-content {
Expand Down
45 changes: 2 additions & 43 deletions src/Elastic.Markdown/Helpers/Htmx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,9 @@
// 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.Text;
using Elastic.Markdown.IO.Configuration;

namespace Elastic.Markdown.Helpers;

public static class Htmx
public class Htmx
{
public static string GetHxSelectOob(FeatureFlags features, string? pathPrefix, string currentUrl, string targetUrl)
{
HashSet<string> selectTargets =
[
"#primary-nav", "#secondary-nav", "#markdown-content", "#toc-nav", "#prev-next-nav", "#breadcrumbs"
];
if (!HasSameTopLevelGroup(pathPrefix, currentUrl, targetUrl) && features.IsPrimaryNavEnabled)
_ = selectTargets.Add("#pages-nav");
return string.Join(',', selectTargets);
}

public static bool HasSameTopLevelGroup(string? pathPrefix, string currentUrl, string targetUrl)
{
var startIndex = pathPrefix?.Length ?? 0;
var currentSegments = GetSegments(currentUrl[startIndex..].Trim('/'));
var targetSegments = GetSegments(targetUrl[startIndex..].Trim('/'));
return currentSegments.Length >= 1 && targetSegments.Length >= 1 && currentSegments[0] == targetSegments[0];
}

public static string GetPreload() => "true";

public static string GetHxSwap() => "none";
public static string GetHxPushUrl() => "true";
public static string GetHxIndicator() => "#htmx-indicator";

private static string[] GetSegments(string url) => url.Split('/');

public static string GetHxAttributes(FeatureFlags features, string? pathPrefix, string currentUrl, string targetUrl)
{

var attributes = new StringBuilder();
_ = attributes.Append($" hx-get={targetUrl}");
_ = attributes.Append($" hx-select-oob={GetHxSelectOob(features, pathPrefix, currentUrl, targetUrl)}");
_ = attributes.Append($" hx-swap={GetHxSwap()}");
_ = attributes.Append($" hx-push-url={GetHxPushUrl()}");
_ = attributes.Append($" hx-indicator={GetHxIndicator()}");
_ = attributes.Append($" preload={GetPreload()}");
return attributes.ToString();
}
public static string GetHxSelectOob() => "#markdown-content,#toc-nav,#prev-next-nav,#breadcrumbs";
}
9 changes: 0 additions & 9 deletions src/Elastic.Markdown/IO/Configuration/ConfigurationFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ public record ConfigurationFile : DocumentationFile
private readonly Dictionary<string, string> _substitutions = new(StringComparer.OrdinalIgnoreCase);
public IReadOnlyDictionary<string, string> Substitutions => _substitutions;

private readonly Dictionary<string, bool> _features = new(StringComparer.OrdinalIgnoreCase);
private FeatureFlags? _featureFlags;
public FeatureFlags Features => _featureFlags ??= new FeatureFlags(_features);

public ConfigurationFile(IFileInfo sourceFile, IDirectoryInfo rootPath, BuildContext context, int depth = 0, string parentPath = "")
: base(sourceFile, rootPath)
{
Expand Down Expand Up @@ -83,9 +79,6 @@ public ConfigurationFile(IFileInfo sourceFile, IDirectoryInfo rootPath, BuildCon

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

public bool IsFeatureEnabled(string feature) => _features.TryGetValue(feature, out var enabled) && enabled;

private List<ITocItem> ReadChildren(YamlStreamReader reader, KeyValuePair<YamlNode, YamlNode> entry, string parentPath)
{
var entries = new List<ITocItem>();
Expand Down
11 changes: 0 additions & 11 deletions src/Elastic.Markdown/IO/Configuration/FeatureFlags.cs

This file was deleted.

11 changes: 1 addition & 10 deletions src/Elastic.Markdown/IO/MarkdownFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,21 +316,12 @@ private YamlFrontMatter ReadYamlFrontMatter(string raw)
}


public string CreateHtml(MarkdownDocument document)
public static string CreateHtml(MarkdownDocument document)
{
//we manually render title and optionally append an applies block embedded in yaml front matter.
var h1 = document.Descendants<HeadingBlock>().FirstOrDefault(h => h.Level == 1);
if (h1 is not null)
_ = document.Remove(h1);
return document.ToHtml(MarkdownParser.Pipeline);
}

public static string CreateHtml(MarkdownDocument document, MarkdownParser parser)
{
//we manually render title and optionally append an applies block embedded in yaml front matter.
var h1 = document.Descendants<HeadingBlock>().FirstOrDefault(h => h.Level == 1);
if (h1 is not null)
_ = document.Remove(h1);
return document.ToHtml(parser.Pipeline);
}
}
18 changes: 11 additions & 7 deletions src/Elastic.Markdown/Myst/Directives/DirectiveHtmlRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Elastic.Markdown.Myst.Directives;
/// An HTML renderer for a <see cref="DirectiveBlock"/>.
/// </summary>
/// <seealso cref="HtmlObjectRenderer{CustomContainer}" />
public class DirectiveHtmlRenderer(MarkdownParser markdownParser) : HtmlObjectRenderer<DirectiveBlock>
public class DirectiveHtmlRenderer : HtmlObjectRenderer<DirectiveBlock>
{
protected override void Write(HtmlRenderer renderer, DirectiveBlock directiveBlock)
{
Expand Down Expand Up @@ -62,10 +62,10 @@ protected override void Write(HtmlRenderer renderer, DirectiveBlock directiveBlo
if (includeBlock.Literal)
WriteLiteralIncludeBlock(renderer, includeBlock);
else
WriteIncludeBlock(renderer, includeBlock, markdownParser);
WriteIncludeBlock(renderer, includeBlock);
return;
case SettingsBlock settingsBlock:
WriteSettingsBlock(renderer, settingsBlock, markdownParser);
WriteSettingsBlock(renderer, settingsBlock);
return;
default:
// if (!string.IsNullOrEmpty(directiveBlock.Info) && !directiveBlock.Info.StartsWith('{'))
Expand Down Expand Up @@ -219,24 +219,28 @@ private static void WriteLiteralIncludeBlock(HtmlRenderer renderer, IncludeBlock
}
}

private static void WriteIncludeBlock(HtmlRenderer renderer, IncludeBlock block, MarkdownParser parser)
private static void WriteIncludeBlock(HtmlRenderer renderer, IncludeBlock block)
{
if (!block.Found || block.IncludePath is null)
return;

var parser = new MarkdownParser(block.Build, block.Context);
var snippet = block.Build.ReadFileSystem.FileInfo.New(block.IncludePath);
var parentPath = block.Context.MarkdownSourcePath;
var document = parser.ParseSnippetAsync(snippet, parentPath, block.Context.YamlFrontMatter, default).GetAwaiter().GetResult();
var html = document.ToHtml(parser.Pipeline);
var html = document.ToHtml(MarkdownParser.Pipeline);
_ = renderer.Write(html);
}

private static void WriteSettingsBlock(HtmlRenderer renderer, SettingsBlock block, MarkdownParser parser)
private static void WriteSettingsBlock(HtmlRenderer renderer, SettingsBlock block)
{
if (!block.Found || block.IncludePath is null)
return;

var parser = new MarkdownParser(block.Build, block.Context);

var file = block.Build.ReadFileSystem.FileInfo.New(block.IncludePath);

YamlSettings? settings;
try
{
Expand All @@ -260,7 +264,7 @@ private static void WriteSettingsBlock(HtmlRenderer renderer, SettingsBlock bloc
RenderMarkdown = s =>
{
var document = parser.ParseEmbeddedMarkdown(s, block.IncludeFrom, block.Context.YamlFrontMatter);
var html = document.ToHtml(parser.Pipeline);
var html = document.ToHtml(MarkdownParser.Pipeline);
return html;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ namespace Elastic.Markdown.Myst.Directives;

public static class DirectiveMarkdownBuilderExtensions
{
public static MarkdownPipelineBuilder UseDirectives(this MarkdownPipelineBuilder pipeline, MarkdownParser markdownParser)
public static MarkdownPipelineBuilder UseDirectives(this MarkdownPipelineBuilder pipeline)
{
pipeline.Extensions.AddIfNotAlready(new DirectiveMarkdownExtension(markdownParser));
pipeline.Extensions.AddIfNotAlready<DirectiveMarkdownExtension>();
return pipeline;
}
}
Expand All @@ -24,7 +24,7 @@ public static MarkdownPipelineBuilder UseDirectives(this MarkdownPipelineBuilder
/// Extension to allow custom containers.
/// </summary>
/// <seealso cref="IMarkdownExtension" />
public class DirectiveMarkdownExtension(MarkdownParser markdownParser) : IMarkdownExtension
public class DirectiveMarkdownExtension : IMarkdownExtension
{
public void Setup(MarkdownPipelineBuilder pipeline)
{
Expand Down Expand Up @@ -53,7 +53,7 @@ public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer)
if (!renderer.ObjectRenderers.Contains<DirectiveHtmlRenderer>())
{
// Must be inserted before CodeBlockRenderer
_ = renderer.ObjectRenderers.InsertBefore<CodeBlockRenderer>(new DirectiveHtmlRenderer(markdownParser));
_ = renderer.ObjectRenderers.InsertBefore<CodeBlockRenderer>(new DirectiveHtmlRenderer());
}

_ = renderer.ObjectRenderers.Replace<HeadingRenderer>(new SectionedHeadingRenderer());
Expand Down
31 changes: 15 additions & 16 deletions src/Elastic.Markdown/Myst/MarkdownParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System.IO.Abstractions;
using Cysharp.IO;
using Elastic.Markdown.IO.Configuration;
using Elastic.Markdown.Myst.CodeBlocks;
using Elastic.Markdown.Myst.Comments;
using Elastic.Markdown.Myst.Directives;
Expand Down Expand Up @@ -102,33 +101,33 @@ private static async Task<MarkdownDocument> ParseAsync(
}

// ReSharper disable once InconsistentNaming
private MarkdownPipeline? _minimalPipelineCached;
private MarkdownPipeline MinimalPipeline
private static MarkdownPipeline? MinimalPipelineCached;
private static MarkdownPipeline MinimalPipeline
{
get
{
if (_minimalPipelineCached is not null)
return _minimalPipelineCached;
if (MinimalPipelineCached is not null)
return MinimalPipelineCached;
var builder = new MarkdownPipelineBuilder()
.UseYamlFrontMatter()
.UseInlineAnchors()
.UseHeadingsWithSlugs()
.UseDirectives(this);
.UseDirectives();

_ = builder.BlockParsers.TryRemove<IndentedCodeBlockParser>();
_minimalPipelineCached = builder.Build();
return _minimalPipelineCached;
MinimalPipelineCached = builder.Build();
return MinimalPipelineCached;
}
}

// ReSharper disable once InconsistentNaming
private MarkdownPipeline? _pipelineCached;
public MarkdownPipeline Pipeline
private static MarkdownPipeline? PipelineCached;
public static MarkdownPipeline Pipeline
{
get
{
if (_pipelineCached is not null)
return _pipelineCached;
if (PipelineCached is not null)
return PipelineCached;

var builder = new MarkdownPipelineBuilder()
.UseInlineAnchors()
Expand All @@ -142,15 +141,15 @@ public MarkdownPipeline Pipeline
.UseYamlFrontMatter()
.UseGridTables()
.UsePipeTables()
.UseDirectives(this)
.UseDirectives()
.UseDefinitionLists()
.UseEnhancedCodeBlocks()
.UseHtmxLinkInlineRenderer(Build)
.UseHtmxLinkInlineRenderer()
.DisableHtml()
.UseHardBreaks();
_ = builder.BlockParsers.TryRemove<IndentedCodeBlockParser>();
_pipelineCached = builder.Build();
return _pipelineCached;
PipelineCached = builder.Build();
return PipelineCached;
}
}

Expand Down
Loading
Loading