Skip to content

Instantly share code, notes, and snippets.

@jcbrinfo
Last active May 9, 2017 15:43
Show Gist options
  • Select an option

  • Save jcbrinfo/9288b7776b3c7717bd5fd62c48001c70 to your computer and use it in GitHub Desktop.

Select an option

Save jcbrinfo/9288b7776b3c7717bd5fd62c48001c70 to your computer and use it in GitHub Desktop.
The universal Markdown comment syntax

The universal Markdown comment syntax

Before

[/]: / "Your comment here"

After

It exploit the “reference-style” link syntax (and workarounds various bugs) to make the egine fully ignore the comment line. So, contrary to a HTML comment, the comment won’t appear in the HTML code.

Results on various engines

http://johnmacfarlane.net/babelmark2/?text=Before%0A%0A%5B%2F%5D%3A+%2F+%22Your+comment+here%22%0A%0AAfter%0A

Things to note

In order to work on any engine, the syntax must follow a lot of rules:

  • The entire comment syntax must be in one line. A multi-line comments must be split into multiple comments.
  • The comment line can only be preceded by the start of the document, an empty line or another link definition (another comment for example).
  • The comment line can only be succeded by the end of the document, an empty line or another link definition (another comment for example).
  • In the same line, nothing can precede the first bracket.
  • The link ID (the text between brackets) must not be empty and must not contain any blank or special character (no space, no \, etc.).
  • The link URL (the lonely slash after the colon above) must be surrounded by a spaces, must not be empty and not contain any blank or special character (no space, no \, no <, no >, etc.).
  • The link URL must not contain #.
  • The link title (the actual comment) must be surrounded US-ASCII quotes ("). Even if specified by the original implementation, parentheses and ' won’t work on many engine.
  • The link title (the actual comment) must not be empty and must no contain ", \ or an end of line.
  • Obviously, this syntax won’t work inside a code block or a raw HTML block.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment