Markdown implementation

Zulip has a special flavor of Markdown, currently called 'bugdown' after Zulip's original name of "humbug". End users are using Bugdown within the client, not original Markdown.

Zulip has two implementations of Bugdown. The backend implementation at zerver/lib/bugdown/ is based on Python-Markdown and is used to authoritatively render messages to HTML (and implements slow/expensive/complex features like querying the Twitter API to render tweets nicely). The frontend implementation is in JavaScript, based on marked.js (static/js/echo.js), and is used to preview and locally echo messages the moment the sender hits enter, without waiting for round trip from the server.

The JavaScript markdown implementation has a function, echo.contains_bugdown, that is used to check whether a message contains any syntax that needs to be rendered to HTML on the backend. If echo.contains_bugdown returns true, the frontend simply won't echo the message for the sender until it receives the rendered HTML from the backend. If there is a bug where echo.contains_bugdown returns false incorrectly, the frontend will discover this when the backend returns the newly sent message, and will update the HTML based on the authoritative backend rendering (which would cause a change in the rendering that is visible only to the sender shortly after a message is sent). As a result, we try to make sure that echo.contains_bugdown is always correct.

Testing

The Python-Markdown implementation is tested by zerver/tests/test_bugdown.py, and the marked.js implementation and echo.contains_bugdown are tested by frontend_tests/node_tests/echo.js. A shared set of fixed test data ("test fixtures") is present in zerver/fixtures/bugdown-data.json, and is automatically used by both test suites; as a result, it the preferred place to add new tests for Zulip's markdown system.

Changing Zulip's markdown processor

When changing Zulip's markdown syntax, you need to update several places:

Important considerations for any changes are:

Zulip's Markdown philosophy

Note that this discussion is based on a comparison with the original Markdown, not newer Markdown variants like CommonMark.

Markdown is great for group chat for the same reason it's been successful in products ranging from blogs to wikis to bug trackers: it's close enough to how people try to express themselves when writing plain text (e.g. emails) that it helps more than getting in the way.

The main issue for using Markdown in instant messaging is that the Markdown standard syntax used in a lot of wikis/blogs has nontrivial error rates, where the author needs to go back and edit the post to fix the formatting after typing it the first time. While that's basically fine when writing a blog, it gets annoying very fast in a chat product; even though you can edit messages to fix formatting mistakes, you don't want to be doing that often. There are basically 2 types of error rates that are important for a product like Zulip:

Both of these are minor issues for most products using Markdown, but they are major problems in the instant messaging context, because one can't edit a message that has already been sent and users are generally writing quickly. Zulip's Markdown strategy is based on the principles of giving users the power they need to express complicated ideas in a chat context while minimizing those two error rates.

Zulip's Changes to Markdown

Below, we document the changes that Zulip has against stock Python-Markdown; some of the features we modify / disable may already be non-standard.

Basic syntax

Lists

Code

Other