This was the next logical step on the interface revamp for 2.0.
The old API was doing very fishy stuff with allocation: the `rndr`
struct was being called once for every `sd_markdown` call, and the
amount stack space filled with it was just inappropriate (256 bytes
just from the char table and 300 more from pointers in the callback
table).
By creating the renderer on the heap and reusing it, we save a lot of
time on initialization code, at the expense of not being able to
change the enabled extensions on each parse (something which is not
that common anyway).
This will make wrapping Sundown in higher level languages more direct,
given that every other language has OO design, which maps better to
the concept of a reusable renderer.
It is by the goodness of God that in our country we have those
three unspeakably precious things:
freedom of speech,
freedom of conscience,
and the prudence never to practice either of them.
-- Mark Twain, Following the Equator (1897)
SmartyPants is no longer an extension flag for the (X)HTML renderer, but
a separate method.
The new function `ups_xhtml_smartypants` external method is a
SmartyPants post-processor that takes an HTML document (e.g. a document
that has just been rendered with `ups_markdown`) and performs
SmartyPants substitutions in it.
This is the same approach that the original SmartyPants takes.
Postprocessing the HTML instead of performing the substitutions at the
Markdown level allows us to work around many problems of the old
implementation:
- Double quotes now properly open/close between different HTML
tags and blocks.
- Support for ``double quoting style'' has been added, and no
longer conflicts with Markdown code blocks.
- The limitations of the Upskirt parser (which was splitting
SmartyPants replacements mid-word in some cases because of active
character callbacks) no longer apply. All SmartyPants substitutions
work in all situations.
- The new parser is easily extendable with more substitutions.
The new SmartyPants parser is slightly faster than the old one.