-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeadingContext.cs
More file actions
39 lines (31 loc) · 1.21 KB
/
Copy pathHeadingContext.cs
File metadata and controls
39 lines (31 loc) · 1.21 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
namespace HelpLine.Docs;
/// <summary>
/// Provides information about a Markdown heading during topic mapping.
/// </summary>
public sealed class HeadingContext
{
private readonly HashSet<string> _topicNames = [];
internal HeadingContext(string headingText, int headingLevel, string? parentHeadingText)
{
HeadingText = headingText;
HeadingLevel = headingLevel;
ParentHeadingText = parentHeadingText;
}
public string HeadingText { get; }
public int HeadingLevel { get; }
/// <summary>
/// The text of the nearest ancestor heading (the most recent heading at a lower level),
/// or <c>null</c> if this is the top-level heading in the document.
/// </summary>
public string? ParentHeadingText { get; }
public void AppendToTopic(string topicName)
{
if (string.IsNullOrWhiteSpace(topicName))
{
throw new ArgumentException("Topic names must be non-empty.", nameof(topicName));
}
var normalized = topicName.Trim().ToLowerInvariant().Replace(' ', '-');
_topicNames.Add(normalized);
}
internal IReadOnlyList<string> MappedTopicNames => _topicNames.ToList();
}