我可以使用 Markdown 在段落上定义类名吗?
我可以使用 Markdown 在段落上定义类名吗? 如果是这样,怎么办?
Can I define a class name on paragraph using Markdown? If so, how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我可以使用 Markdown 在段落上定义类名吗? 如果是这样,怎么办?
Can I define a class name on paragraph using Markdown? If so, how?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(10)
欺骗:如何在 Markdown 中设置 HTML 类属性?
本地? 不,但是……
不,Markdown 的语法不能。 您可以通过 Markdown Extra设置 ID 值。
如果您愿意,可以使用常规 HTML,并添加属性
markdown="1"
继续降价转换HTML 元素内。 不过,这需要 Markdown Extra。可能的解决方案:(未经测试,用于
我在网上找到了以下内容:
Function
Markdown
Result
Dupe: How do I set an HTML class attribute in Markdown?
Natively? No. But...
No, Markdown's syntax can't. You can set ID values with Markdown Extra through.
You can use regular HTML if you like, and add the attribute
markdown="1"
to continue markdown-conversion within the HTML element. This requires Markdown Extra though.Possible Solution: (Untested and intended for
<blockquote>
)I found the following online:
Function
Markdown
Result
原始 HTML 实际上在 Markdown 中是完全有效的。 例如:
只需确保 HTML 不在代码块内即可。
Raw HTML is actually perfectly valid in markdown. For instance:
Just make sure the HTML is not inside a code block.
如果您的环境是 JavaScript,请使用 markdown-it 以及插件 markdown-it-attrs:
输出
jsfiddle
注意: 在 Markdown 中允许属性时请注意安全问题!
免责声明,我是 markdown-it-attrs 的作者。
If your environment is JavaScript, use markdown-it along with the plugin markdown-it-attrs:
Output
jsfiddle
Note: Be aware of the security aspect when allowing attributes in your markdown!
Disclaimer, I'm the author of markdown-it-attrs.
如果你的 markdown 风格是 kramdown,那么你可以像这样设置 css 类:
然后在你的 css 文件中,你可以这样设置 css:
If your flavour of markdown is kramdown, then you can set css class like this:
Then in you css file, you set the css like this:
Markdown应该具有此功能,但它没有。 相反,您只能使用特定于语言的 Markdown 超集:
PHP: Markdown额外
Ruby: Kramdown、Maruku
但是,如果您需要遵守真正的 Markdown 语法,那么您将不得不插入原始 HTML,这不太理想。
Markdown should have this capability, but it doesn't. Instead, you're stuck with language-specific Markdown supersets:
PHP: Markdown Extra
Ruby: Kramdown, Maruku
But if you need to abide by true Markdown syntax, you're stuck with inserting raw HTML, which is less ideal.
这是一个遵循 @Yarin 答案的 kramdown 的工作示例。
参考: https://kramdown.gettalong.org/syntax.html#inline-attribute -列表
Here is a working example for kramdown following @Yarin's answer.
Reference: https://kramdown.gettalong.org/syntax.html#inline-attribute-lists
正如上面提到的,降价本身让你坚持这一点。 但是,根据实现的不同,有一些解决方法:
至少有一个版本的 MD 认为
是块级标记,但
只是文本。 然而,所有浏览器都不区分大小写。 这允许您保持 MD 的语法简单性,但代价是添加 div 容器标签。
因此,以下是一种解决方法:
这样做的缺点是输出代码具有包裹
行的
标记(两者,第一个因为它不是,第二个因为它不匹配,我发现没有浏览器对此大惊小怪,但 MD 往往会放入备用的
标签。无论如何,
Markdown 的多个版本都实现了
约定,在这种情况下,MD 将在标记内进行正常处理。 上面的示例变为:Fletcher 的当前版本 < em>MultiMarkdown 如果使用引用链接,则允许属性跟随链接。
As mentioned above markdown itself leaves you hanging on this. However, depending on the implementation there are some workarounds:
At least one version of MD considers
<div>
to be a block level tag but<DIV>
is just text. All broswers however are case insensitive. This allows you to keep the syntax simplicity of MD, at the cost of adding div container tags.So the following is a workaround:
The downside of this is that the output code has
<p>
tags wrapping the<div>
lines (both of them, the first because it's not and the second because it doesn't match. No browser fusses about this that I've found, but the code won't validate. MD tends to put in spare<p>
tags anyway.Several versions of markdown implement the convention
<tag markdown="1">
in which case MD will do the normal processing inside the tag. The above example becomes:The current version of Fletcher's MultiMarkdown allows attributes to follow the link if using referenced links.
还应该提到的是
标签允许在它们内部 - 块级项目在它们内部本身就否定 MD,除非您将它们配置为不这样做,但内联样式本身允许在它们内部使用 MD他们。 因此,我经常做类似的事情......
我不能 100% 确定这是否通用,但在我使用过的所有 MD 编辑器中似乎都是这种情况。
It should also be mentioned that
<span>
tags allow inside them -- block-level items negate MD natively inside them unless you configure them not to do so, but in-line styles natively allow MD within them. As such, I often do something akin to...I am not 100% sure if this is universal but seems to be the case in all MD editors I've used.
在 slim markdown 中使用:
翻译为:
In slim markdown use this:
Translates to:
如果您只需要用于 Javascript 目的的选择器(就像我一样),您可能只想使用
href
属性而不是class
或id
:只需这样做:
Markdown 不会像对待类和 id 那样忽略或删除
href
属性。所以在你的 Javascript 或 jQuery 中你可以这样做:
至少这在我的 Markdown 版本中有效......
If you just need a selector for Javascript purposes (like I did), you might just want to use a
href
attribute instead of aclass
orid
:Just do this:
Markdown will not ignore or remove the
href
attribute like it does with classes and ids.So in your Javascript or jQuery you can then do:
At least this works in my version of Markdown...