如何在Markdown中居中一个项目?我正在寻找一个适用于Grav的解决方案。
Markdown本身不支持此功能,但是您可以通过将Markdown包裹在HTML中来实现。
一般来说,大多数Markdown格式将呈现为居中文本:
<p style="text-align: center;">Centered text</p>
针对Grav,正如他们的文档所述,您应该执行以下步骤:
在您的系统配置文件user/config/system.yaml
中,确保激活markdown extra选项:
pages:
markdown:
extra: true
在您的包装标签中,确保添加参数markdown="1"
以激活处理Markdown内容的功能:<div class="myWrapper" markdown="1">
# my markdown content
this content is wrapped into a div with class "myWrapper"
</div>
<div align="center">
align
属性已经被弃用。 - TechySharnav当使用任何元素,比如标题时,可以使用等效的HTML标签,例如:
# Title
## title 2
等同于
<h1> Title </h1>
<h2> Title 2 </h2>
例如,使用以下属性之一,您可以通过标题对齐文本:
<!-- title only -->
<h1 align="center"> Title </h1>
<!-- title with div -->
<div align="center"> <h1 align="center"> Title inside div! </h1> </div>
但有时您不想使用 HTML,因为它会破坏在其中使用 markdown 的能力,在这些情况下,您可以使用 span,它允许您在 HTML 标签中呈现 markdown:
<!-- title with span (you can render emojis or markdown inside it) -->
<span align="center"> <h1> :star: My Career: </h1> </span>