How do I set an HTML class attribute in Markdown?

Markdown Extra supports class and id attributes using curly braces. See: https://michelf.ca/projects/php-markdown/extra/#spe-attr


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


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


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 { }
```

Tags:

Html

Markdown