I have a question about how the answer is rendered. I have noticed that many HTML codes seem to work in the preview of the answer but don't appear the final answer. Why are these blocked?
1 Answer
The short answer is we use two different Markdown libraries to render the preview and the final answer. These two different libraries treat HTML differently.
Our answers are styled and formatted using a markup language called "Markdown." Markdown converts predefined markup into HTML for links, images, headers, italics, emphases, etc.
Without getting too technical, our answer preview is created in the browser using a Javascript library. We do this for speed reasons.
When you refresh the page, the answer is already converted to HTML using our Python Markdown library. We do this because we want the answer to look great as soon as you get to the page. If we decided to simply output the raw answer and then convert it using our Javascript library, you'd notice first the "ugly" raw answer and then a jump into the nicely formatted version. That's not so bad, but the problem is that Google and other bots that crawl our site for search do not run Javascript. Those bots would always see the raw, ugly answer which could hurt our search ranking.
Now, why do these two libraries treat HTML codes differently? The Python library responsible for the final answer "escapes" HTML, meaning it takes those HTML codes and changes them to harmless text. I say harmless because you can imagine allowing users to input HTML into our page can completely destroy the layout of the page. The Javascript library responsible for the preview does NOT escape HTML, which is technically a bug.
In the future, we'll have to remove the ability of Javascript library to preview HTML codes for security reasons. We'll also move to using a single library to render all of our Markdown text.