如何在 Markdown 中设置 HTML 类属性?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/975264/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 23:52:39  来源:igfitidea点击:

How do I set an HTML class attribute in Markdown?

htmlmarkdown

提问by James A. Rosen

If I have some Markdown like

如果我有一些 Markdown 之类的

## 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>在中间生成的块上设置类?我想让它输出

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

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

但是我好像不能设置。我无法控制正在运行的 Markdown 代码,只能控制内容。

回答by Patrick McElhaney

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

您可以在 Markdown 中嵌入 HTML。只需按字面意思输入您想要的内容,无需缩进。

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

回答by Pablo Olmos de Aguilera C.

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

虽然没有准确回答问题。您也可以使用不同的渲染,例如 Maruku 或 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):

输出(使用 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

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

回答by Psion

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

Markdown 有一个扩展 ( attr_list.py),它允许您使用 Maruku 的{: .classname}语法。

回答by jeffmcneill

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

Markdown Extra 支持使用花括号的 class 和 id 属性。请参阅:https: //michilf.ca/projects/php-markdown/extra/#spe-attr