首页 > 解决方案 > 在新的 CSS 段落选择器中保留 .md 格式

问题描述

在 Hugo 网站的 .css 中,我创建了一个新的选择器来执行 MLA 格式的引用缩进:

.mla-ref {
    padding-left: 36px;
    text-indent: -36px;
}

这按预期工作,创建了一个悬挂缩进。但是,不应用降价格式。例如,我得到一个带有星号的标题:*Moby Dick*

我可以在上面的 .css 项目中做些什么来保留斜体的降价格式吗?

标签: cssmarkdownhugo

解决方案


降价到HTML

AFAIK,例如,您不能将输入 markdown 包装到语义部分中,就像使用 straight 一样HTML。你从中得到什么

# First
This is the first paragraph of the first section.

This is the second paragraph of the first section.

# Second
This is the first paragraph of the second section.

只是一堆

<h1 id="first">First</h1>
<p>This is the first paragraph of the first section.</p>
<p>This is the second paragraph of the first section.</p>
<h1 id="second">Second</h1>
<p>This is the first paragraph of the second section.</p>

与那些id由标题的内容生成的。

我猜这使得编写内容和解析器变得容易,但很难仅对某些元素应用自定义样式。

雨果中的降价

根据配置标记文档, Hugo 0.60+ 使用goldmark作为解析的默认库。Markdown

显然,goldmark 支持自定义属性,但仅适用于标题。

## heading {#id .className attrName=attrValue class="class1 class2"}

这意味着至少现在,您只能用一个.has-mla-ref类标记一个标题,然后将样式应用于直接兄弟。

例子

.has-mla-ref + p {
    padding-left: 36px;
    text-indent: -36px;
}
### Reference {.has-mla-ref}

Best, David, and Sharon Marcus. “Surface Reading: An Introduction.” Representations, vol. 108, no. 1, Fall 2009, pp. 1-21. JSTOR, doi:10.1525/rep.2009.108.1.1

Onwards with your content, this is not a ref anymore.

我不知道它是否不仅仅是为了使其符合 MLA 格式的缩进,或者您需要的不仅仅是一个段落,但希望这能让您走上正确的轨道。


推荐阅读