public SectionRef(MarkdownParagraph.Heading mdh, string filename) { Level = mdh.size; var spans = mdh.body; if (spans.Length == 1 && spans.First().IsLiteral) { Title = MarkdownUtilities.UnescapeLiteral(spans.First() as MarkdownSpan.Literal).Trim(); if (char.IsDigit(Title[0]) || (Title[0] >= 'A' && Title[0] <= 'D' && Title[1] == '.')) { var titleParts = Title.Split(new[] { ' ' }, 2); Number = titleParts[0]; TitleWithoutNumber = titleParts[1]; } else { Number = null; TitleWithoutNumber = Title; } } else { throw new NotSupportedException($"Heading must be a single literal. Got: {mdh.body}"); } foreach (var c in Title) { if (c >= 'a' && c <= 'z') { Url += c; } else if (c >= 'A' && c <= 'Z') { Url += char.ToLowerInvariant(c); } else if (c >= '0' && c <= '9') { Url += c; } else if (c == '-' || c == '_') { Url += c; } else if (c == ' ') { Url += '-'; } } Url = filename + "#" + Url; BookmarkName = $"_Toc{count:00000}"; count++; Loc = new SourceLocation(filename, this, mdh, null); }
public SectionRef(MarkdownParagraph.Heading mdh, string filename) { Level = mdh.Item1; var spans = mdh.Item2; if (spans.Length == 1 && spans.First().IsLiteral) { Title = mdunescape(spans.First() as MarkdownSpan.Literal).Trim(); } else if (spans.Length == 1 && spans.First().IsInlineCode) { Title = (spans.First() as MarkdownSpan.InlineCode).Item.Trim(); } else { throw new NotSupportedException("Heading must be a single literal/inlinecode"); } foreach (var c in Title) { if (c >= 'a' && c <= 'z') { Url += c; } else if (c >= 'A' && c <= 'Z') { Url += char.ToLowerInvariant(c); } else if (c >= '0' && c <= '9') { Url += c; } else if (c == '-' || c == '_') { Url += c; } else if (c == ' ') { Url += '-'; } } Url = filename + "#" + Url; BookmarkName = $"_Toc{count:00000}"; count++; }