Typographic punctuation
editA 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 “, «, …, –, —...
var options = new MarkdownParseOptions { Extensions = MarkdownExtensions.SmartyPants };
var tree = MarkdownSyntaxTree.ParseText("\"Wait...\" -- it is 'done'\n", options);
Assert.Equal("<p>“Wait…” – it is ‘done’</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…\u00A0\u00BB – it is ‘done’</p>\n", MarkdownHtmlRenderer.ToHtml(tree, french));Details
- A quote is typographic when it opens or closes as
_would, and only when it is paired, sol'amikeeps its apostrophe. - Each one is a token of kind SmartyPantToken, whose value is a MarkdownSmartyPant.
- MarkdownHtmlRendererOptions.SmartyPants changes the HTML that the renderer writes for them, for instance for the quotes of another language.