Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set an HTML class attribute in Markdown?

Tags:

html

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.

like image 790
James A. Rosen Avatar asked Jun 10 '09 12:06

James A. Rosen


People also ask

Can you add classes to markdown?

No, Markdown's syntax can't.


1 Answers

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 { } ``` 
like image 194
Patrick McElhaney Avatar answered Sep 28 '22 14:09

Patrick McElhaney