/TestMarkDown

Small example testing MarkDig

Primary LanguageC#

This code is a C# program that uses the Markdig library to parse a markdown file named TestMarkDown.md and extract its headers. Here's a breakdown of what the code does:

  1. The program starts by reading the contents of the TestMarkDown.md file into a string variable named markdown.
  2. The markdown string is then processed to replace all occurrences of the \r\n newline sequence with the newline sequence used by the current environment, as determined by the Environment.NewLine property.
  3. A new MarkdownPipeline object is created using the MarkdownPipelineBuilder class and its Build method. This pipeline object is used to configure how the markdown text will be parsed.
  4. The Markdown.Parse method is called to parse the markdown string using the specified pipeline. The result is a MarkdownDocument object that represents the structure of the markdown text.
  5. The Descendants<HeadingBlock> method is called on the document object to get an enumerable collection of all heading blocks in the document.
  6. The program then enters a loop that iterates over each heading block in the collection.
  7. For each heading block, the first inline element is extracted using the FirstOrDefault method.
  8. If the inline element is of type LiteralInline, its content is written to the console using the Console.WriteLine method.

In summary, this code reads a markdown file, parses it, and extracts and prints its headers to the console.