How do I set an HTML class attribute in Markdown?

Solution 1:

You can embed HTML in Markdown. Type literally what you want, with no indent.

<code class="prettyprint">
  code_line(1);
  // a code comment
  class More Code { }
</code>

For the specific case of syntax highlighting following the back ticks at the start of a fenced code block with the language works just about everywhere these days.

```js
code_line(1);
// a code comment
class MoreCode { }
```

Solution 2:

Though not answering the question exactly. You can use a different render too like Maruku or Kramdown:

## My Title

A paragraph of content here.
~~~
code_line(1);
// a code comment
class MoreCode { }
~~~
{: .prettyprint}

and more text to follow...

Output (tested with haml & kramdown):

<pre class="prettyprint"><code>
code_line(1);
// a code comment
class MoreCode { }
</code></pre>

Kramdown syntax: http://kramdown.rubyforge.org/quickref.html#block-attributes

Solution 3:

Markdown has an extension (attr_list.py) which allows you to use Maruku's {: .classname} syntax.