Typographic punctuation

edit

A keyboard types straight quotes and hyphens, while print uses curly quotes, dashes and ellipses. SmartyPants writes them as their typographic characters: quotes, << and >>, ... at the end of a word, -- and --- become &ldquo;, &laquo;, &hellip;, &ndash;, &mdash;...

var options = new MarkdownParseOptions { Extensions = MarkdownExtensions.SmartyPants };
var tree = MarkdownSyntaxTree.ParseText("\"Wait...\" -- it is 'done'\n", options);

Assert.Equal("<p>&ldquo;Wait&hellip;&rdquo; &ndash; it is &lsquo;done&rsquo;</p>\n", MarkdownHtmlRenderer.ToHtml(tree));

// The renderer can write other text, such as the characters themselves
var french = new MarkdownHtmlRendererOptions
{
    SmartyPants = new Dictionary<MarkdownSmartyPant, string>
    {
        [MarkdownSmartyPant.LeftDoubleQuote] = "\u00AB\u00A0",
        [MarkdownSmartyPant.RightDoubleQuote] = "\u00A0\u00BB",
    },
};
Assert.Equal("<p>\u00AB\u00A0Wait&hellip;\u00A0\u00BB &ndash; it is &lsquo;done&rsquo;</p>\n", MarkdownHtmlRenderer.ToHtml(tree, french));

Details