Comments in Markdown

in «tip» by Michael Beard
Tags: , , , , ,

I ran across a situation where I'd like to create a comment in a Markdown document, but didn't know how. So, I looked it up. Here is what I found:

Comments in Markdown - this gives several that could be used, so ...

Using the answer by Magnus, I see these:

  • [comment]: <> (This is a comment, it will not be included)
  • [//]: <> (This is also a comment.)
  • [//]: # (This may be the most platform independent comment)

The last seems to be the best, as it's probably more platform dependent.

Note: it seems that you need to have a blank line before (and potentially after) any comment(s) or it might not work. It's interesting to note that multiline comments should work, but ... Something to play with.

(emply line)
[//]: # (This may be the most platform independent comment)

Zenexer had this to say though, so ... food for thought:

[//]: # "Comment" and [//]: # (Comment) seem to work on a wider variety of implementations, because # is a valid relative URI. GitHub, for example, rejects <>, and the entire line becomes visible. It's also worth noting that link labels often need to be separated from other content by a blank line. – Zenexer Mar 5 '14 at 0:17

Another good answer is by chi:

<!---
your comment goes here
and here
-->

This might be the better answer for what I want/need, so ...

Here is another good article: Markdown comments syntax: Comments that won’t appear in generated output.

As the author, Alvin Alexander says

This syntax is ugly and I’ll never remember it, but I guess that’s what macros are for. I’ve read that some people have no idea why someone would want to create comments in Markdown text, and to that I reply, “Try writing a book.”

My need for comments in Markdown

What I'd like to do is use something like this to embed Python Cog scripts in it to generate a visual (for printing out a document) of all the links I use in a document, but without having to maintain two lists (see referenced links for Markdown).

Some text with [a link][1] and
another [link][2].

[1]: http://example.com/ "Title for com"
[2]: http://example.org/ "Title for org"

I could generate an inserted section that would show a referenced section that would look something like this:

#### References

* 1 - *Title for com* - http://example.com/
* 2 - *Title for org* - http://example.org/

That way, if a document is printed, it will have the underlined links, but that doesn't help the reader if they want to know what the actual link is! This would help.