James A. Rosen James A. Rosen - 4 months ago 24
Markdown Question

How do I set an HTML class attribute in Markdown?

If I have some Markdown like

## My Title

A paragraph of content here.

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

and more text to follow...


How can I set a class on the
<code>
block that's generated in the middle there? I want to have it output

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


But I can't seem to set it. I do not have control over the Markdown code being run, only over the content.

Answer

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

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