Code

var myStrings = new[] { "John", "Paul", "Ringo", "George" };
Console.Write(myStrings.ToMarkdownBulletedList());

HTML

Code

var files = new DirectoryInfo(@"C:\MarkdownLog").EnumerateFiles();
Console.Write(files.ToMarkdownNumberedList(i => i.Name + " is " + i.Length + " bytes"));

HTML

  1. appveyor.yml is 302 bytes
  2. LICENSE is 1088 bytes
  3. MarkdownLog.sln is 1480 bytes
  4. README.md is 6173 bytes

Code

var data = new[]
{
    new{Name = "Meryl Streep", Nominations = 18, Awards=3},
    new{Name = "Katharine Hepburn", Nominations = 12, Awards=4},
    new{Name = "Jack Nicholson", Nominations = 12, Awards=3}
};

Console.Write(data.ToMarkdownTable());

HTML

Name Nominations Awards
Meryl Streep 18 3
Katharine Hepburn 12 4
Jack Nicholson 12 3

Note: A GitHub Flavoured parser is required to produce a true HTML table from the Markdown that is produced. A basic Markdown parser will output the table as a standard code block

Code

var data = new[]
    {
        new{Name = "Meryl Streep", Nominations = 18, Awards=3},
        new{Name = "Katharine Hepburn", Nominations = 12, Awards=4},
        new{Name = "Jack Nicholson", Nominations = 12, Awards=3}
    };

var tableWithHeaders = data
            .ToMarkdownTable(i => i.Name, i => i.Nominations + i.Awards)
            .WithHeaders("Name", "Total");

 Console.Write(tableWithHeaders);

HTML

Name Total
Meryl Streep 21
Katharine Hepburn 16
Jack Nicholson 15

Code

var worldCup = new Dictionary<string, int>
{
    {"Brazil", 5},
    {"Italy", 4},
    {"Germany", 4},
    {"Argentina", 2},
    {"Uruguay", 2},
    {"France", 1},
    {"Spain", 1},
    {"England", 1}
}; 

Console.Write(worldCup.ToMarkdownBarChart());

HTML


    Brazil    |#####  5
    Italy     |####  4
    Germany   |####  4
    Argentina |##  2
    Uruguay   |##  2
    France    |#  1
    Spain     |#  1
    England   |#  1
              ------

Code

const int valueCount = 20;
var chart = new BarChart
{
    ScaleAlways = true,
    MaximumChartWidth = 40,
    DataPoints = from i in Enumerable.Range(0, valueCount)
        let rad = (i * 2.0 * Math.PI) / valueCount
        select new BarChartDataPoint
        {
            CategoryName = string.Format("Cos({0:0.0})", rad),
            Value = Math.Cos(rad)
        }
};

Console.Write(chart.ToMarkdownBarChart());

HTML


    Cos(0.0)                     |####################  1
    Cos(0.3)                     |###################  0.95
    Cos(0.6)                     |################  0.81
    Cos(0.9)                     |############  0.59
    Cos(1.3)                     |######  0.31
    Cos(1.6)                     |  0
    Cos(1.9)               ######|  -0.31
    Cos(2.2)         ############|  -0.59
    Cos(2.5)     ################|  -0.81
    Cos(2.8)  ###################|  -0.95
    Cos(3.1) ####################|  -1
    Cos(3.5)  ###################|  -0.95
    Cos(3.8)     ################|  -0.81
    Cos(4.1)         ############|  -0.59
    Cos(4.4)               ######|  -0.31
    Cos(4.7)                     |  0
    Cos(5.0)                     |######  0.31
    Cos(5.3)                     |############  0.59
    Cos(5.7)                     |################  0.81
    Cos(6.0)                     |###################  0.95
             -----------------------------------------

Code

Console.Write("The Origin of the Species".ToMarkdownHeader());

HTML

The Origin of the Species

Code

Console.Write("By Means of Natural Selection".ToMarkdownSubHeader());

HTML

By Means of Natural Selection

Code

const string text = "There are only two hard things in computer science:\n" +
                "cache invalidation,\n" + 
                "naming things,\n" +
                "and off-by-one errors.";

Console.Write(text.ToMarkdownBlockquote());

HTML

Lolita, light of my life, fire of my loins. My sin, my soul. Lo-lee-ta: the tip of the tongue taking a trip of three steps down the palate to tap, at three, on the teeth. Lo. Lee. Ta.

Code

const string text = "There are only two hard things in computer science:\n" +
                    "cache invalidation,\n" + 
                    "naming things,\n" +
                    "and off-by-one errors.";

Console.Write(text.ToMarkdownBlockquote());

HTML

There are only two hard things in computer science:
cache invalidation,
naming things,
and off-by-one errors.

Code

var blockQuote = new Blockquote();

blockQuote.Append(new HorizontalRule());
blockQuote.Append(new Header("COMPUTING MACHINERY AND INTELLIGENCE"));
blockQuote.Append(new SubHeader("By A. M. Turing."));

blockQuote.Append(new Paragraph("..."));

blockQuote.Append(new Paragraph("The idea behind digital computers may be explained by saying that these machines are intended to carry out any operations which could be done by a human computer. The human computer is supposed to be following fixed rules; he has no authority to deviate from them in any detail. We may suppose that these rules are supplied in a book, which is altered whenever he is put on to a new job. He has also an unlimited supply of paper on which he does his calculations. He may also do his multiplications and additions on a \"desk machine,\" but this is not important."));
blockQuote.Append(new Paragraph("If we use the above explanation as a definition we shall be in danger of circularity of argument. We avoid this by giving an outline. of the means by which the desired effect is achieved. A digital computer can usually be regarded as consisting of three parts:"));

blockQuote.Append(new NumberedList("Store", "Executive unit", "Control"));

Console.Write(blockQuote);

HTML


COMPUTING MACHINERY AND INTELLIGENCE

By A. M. Turing.

...

The idea behind digital computers may be explained by saying that these
machines are intended to carry out any operations which could be done by a
human computer. The human computer is supposed to be following fixed rules; he
has no authority to deviate from them in any detail. We may suppose that these
rules are supplied in a book, which is altered whenever he is put on to a new
job. He has also an unlimited supply of paper on which he does his
calculations. He may also do his multiplications and additions on a "desk
machine," but this is not important.

If we use the above explanation as a definition we shall be in danger of
circularity of argument. We avoid this by giving an outline. of the means by
which the desired effect is achieved. A digital computer can usually be
regarded as consisting of three parts:

  1. Store
  2. Executive unit
  3. Control

Code

var log = new MarkdownContainer();

var countries = new[]{"Zimbabwe", "Italy", "Bolivia", "Finland", "Australia"};

log.Append("Countries (unsorted)".ToMarkdownHeader());
log.Append(countries.ToMarkdownNumberedList());

var sorted = countries.OrderBy(i => i);

log.Append("Countries (sorted)".ToMarkdownHeader());
log.Append(sorted.ToMarkdownNumberedList());

Console.Write(log);

HTML

Countries (unsorted)

  1. Zimbabwe
  2. Italy
  3. Bolivia
  4. Finland
  5. Australia

Countries (sorted)

  1. Australia
  2. Bolivia
  3. Finland
  4. Italy
  5. Zimbabwe
Return to Article