kytrinyx/exercism.io — pull request #899 by toolness (2013-10-22 21:12:14+00:00)
Title: [Work In Progress] First attempt at hyperlinking mentions inline (see #877).

I'm doing the hyperlinking by parsing the generated Markdown HTML into a DOM tree using Nokogiri, and then modifying the DOM tree in-place by finding text nodes containing mentions, ignoring everything in code blocks. The DOM is then re-serialized to HTML and returned by the Markdown renderer in `lib/exercism/markdown.rb`.

This is the only way I know of doing the hyperlinking that both gives us control over where the hyperlinking occurs, as well as preventing XSS vulnerabilities from creeping into our code. I also looked into the Redcarpet API, but it didn't seem to give us the same flexibility.

Because of the extra re-serialization that occurs during the post-processing of the rendered Markdown, HTML output isn't *exactly* the same as it was before, though it still has the same basic DOM structure. See the change in the expected output of the `test_newlines` test in `MarkdownTest` for an example of this.

I'm guessing that since the rendering now effectively enumerates all the mentions, we might want to have it return some kind of object containing both the rendered HTML as well as the list of mentions, obviating the need for the `ExtractsMentionsFromMarkdown` class.

Things that still need to be done:

* Right now we don't ensure that there are only spaces/punctuation around the mention, meaning e.g. our code would think `hi@toolness.com` contains a mention of `@toolness`. However, I *think* the `ExtractsMentionsFromMarkdown` class has the same limitation (not sure though).
* A class `mention` is given to the hyperlink but it's not actually given any special display via CSS.
* The list of mentions are still enumerated after the comment, but should be removed as per the discussion in #877.
* Probably other stuff I'm forgetting about!

Also, as I am a complete Ruby noob, the code I've added here is probably terrible. Suggestions are welcome!