Markdown comments

John Gruber gruber at fedora.net
Mon Sep 18 11:09:06 EDT 2006


Michel Fortin <michel.fortin at michelf.com> wrote on 9/17/06 at 9:51 PM:


> Maybe Markdown should do something about double-hyphens inside

> comments. This way, a user could comment out any piece of Markdown

> text -- like this paragraph -- without having to worry about the

> double hyphens it contains.


So what can we have it turn "--" into? An obvious answer is
em-dashes, but then you run into the problem of text encoding.

We could backslash escape them.



> As a downside, it may encourage some people to write badly-formed XML

> and HTML comments elsewhere on the web.


Well, if Markdown somehow magically protects you from generating
invalid XML comments containing "__", I don't see how it's any
more likely to make you write badly-formed comments elsewhere than
if Markdown simply does nothing about the problem, and it "just
works" anyway in all modern web browsers.

So here's my proposal for Markdown comments:

Starts with:

<!--

Ends with first instance of:

-->

Between start and end, any run of N consecutive dash characters,
where N > 1, e.g.:

--
---
----------------

is replaced with a dash followed by N - 1 backslash-dash sequences:

-\-
-\-\-
-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-

And, before this dash-fixing takes place, any existing backslash-dash sequences would be turned into backslash-backslash-dash.

So, given this Markdown input:

<!-- -- \- -->

Output:

<!-- -\- \\- -->

-J.G.


More information about the Markdown-Discuss mailing list