Пример #1
0
        internal static async Task <FrontMatterParseResult> TryReadFrontMatter(TextReader input)
        {
            // Create a string builder to capture any content outside the front matter that we have to read to find the front matter
            StringBuilder nonMatterBuilder = new StringBuilder();

            // Read lines until the first non-whitespace one
            string line = null;

            while (string.IsNullOrWhiteSpace(line = await input.ReadLineAsync()))
            {
                nonMatterBuilder.AppendLine(line);
            }

            // Ok, now we have the first non-whitespace line. Check for front matter
            FrontMatter frontMatter = null;

            if (string.Equals(line.Trim(), Delimiter, StringComparison.Ordinal))
            {
                // It is! Read until the end of the front matter
                StringBuilder frontMatterContent = new StringBuilder();
                while (!string.Equals(line = await input.ReadLineAsync(), Delimiter, StringComparison.Ordinal))
                {
                    frontMatterContent.AppendLine(line);
                }

                // Input is positioned at the first non-front matter content, so we're done!
                frontMatter = new FrontMatter(BadYamlParser.Parse(frontMatterContent.ToString()));
            }
            else
            {
                // Not front-matter, put the line in the content (along with a terminator)
                nonMatterBuilder.AppendLine(line);
            }

            return(new FrontMatterParseResult(
                       frontMatter,
                       nonMatterBuilder.ToString()));
        }
Пример #2
0
 public DocumentationPage(string fileName, FrontMatter frontMatter, HtmlString content)
 {
     FileName    = fileName;
     FrontMatter = frontMatter;
     Content     = content;
 }
Пример #3
0
 public FrontMatterParseResult(FrontMatter frontMatter, string nonFrontMatterContent)
 {
     FrontMatter           = frontMatter;
     NonFrontMatterContent = nonFrontMatterContent;
 }