The current situation is incredibly hacky, because char_link has to reach into the output buffer to remove the last exclamation mark. For a non-standard renderer that does not just echo normal text to the output, this doesn't work well.
`find_emph_char` returns 0 if the char specified is not found in the
current line, but this is also what happens when there's an empty
cell. This patch adds logic to work around this problem.
See uranusjr/macdown#321
When the `HOEDOWN_EXT_UNDERLINE` extension was enabled, underlined spans
would actually be passed verbatim to the output buffer. This was because
the active_char was _only_ set when the emphasis, double_emphasis, or
triple_emphasis handlers were registered. As a result, no active char
was found in the input buffer, so everything was passed through
verbatim.
This patch fixes this by also registering the `active_char` if the
underline handler is registered. I also added a simple regression test.
I personally don't use this extension, but I encountered this bug over
the course of writing bindings for Rust.
Before this patch, a header like "# *A*" was displayed as
"<li><em>A</em></li>" in the TOC. The error was caused by
toc_header doing the HTML escaping. In the normal HTML renderer, the escaping
is done by the normal_text hook. This patch uses the same handling to
fix the issue.