-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathCliRootFile.cs
More file actions
61 lines (53 loc) · 1.97 KB
/
Copy pathCliRootFile.cs
File metadata and controls
61 lines (53 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// 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.IO.Abstractions;
using Elastic.Documentation.Configuration;
using Elastic.Documentation.Configuration.Toc.CliReference;
using Elastic.Markdown.Myst;
using Markdig.Syntax;
namespace Elastic.Markdown.Extensions.CliReference;
public record CliRootFile : IO.MarkdownFile
{
private readonly CliSchema _schema;
private readonly IFileInfo? _supplementalDoc;
private readonly string _title;
private readonly string _navigationTitle;
public CliRootFile(
IFileInfo sourceFile,
IDirectoryInfo rootPath,
MarkdownParser parser,
BuildContext build,
CliSchema schema,
IFileInfo? supplementalDoc,
string? title = null,
string? navigationTitle = null
) : base(sourceFile, rootPath, parser, build)
{
_schema = schema;
_supplementalDoc = supplementalDoc;
_title = string.IsNullOrWhiteSpace(title) ? schema.Name : title.Trim();
_navigationTitle = string.IsNullOrWhiteSpace(navigationTitle) ? $"{schema.Name} CLI" : navigationTitle.Trim();
Title = _title;
}
public override string NavigationTitle => _navigationTitle;
protected override Task<MarkdownDocument> GetMinimalParseDocumentAsync(Cancel ctx)
{
Title = _title;
var markdown = BuildMarkdown();
return Task.FromResult(MarkdownParser.MinimalParseStringAsync(markdown, SourceFile, null));
}
protected override Task<MarkdownDocument> GetParseDocumentAsync(Cancel ctx)
{
var markdown = BuildMarkdown();
return Task.FromResult(MarkdownParser.ParseStringAsync(markdown, SourceFile, null));
}
private string BuildMarkdown()
{
var rawSupplemental = _supplementalDoc?.Exists == true
? _supplementalDoc.FileSystem.File.ReadAllText(_supplementalDoc.FullName)
: null;
var supplemental = CliSupplementalDoc.Parse(rawSupplemental);
return CliMarkdownGenerator.RootPage(_schema, supplemental, _title);
}
}