在新的 CSS 段落选择器中保留 .md 格式

Preserve .md formatting in a new CSS paragraph selector

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

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

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

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

减价到 HTML

AFAIK,您不能将输入的降价包装成语义部分,例如,就像直接 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 中的 Markdown

Hugo 0.60+ 使用 goldmark as the default library for parsing Markdown, as per the Configure Markup docs.

显然,goldmark 支持 custom attributes,但仅用于标题。

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

这意味着至少现在,您只能使用 .has-mla-ref class 标记标题,然后将样式应用到直接同级。

例子

.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 格式,或者您是否需要的不仅仅是一个段落,但希望这能让您走上正轨。

所以答案是创建一个这样的短代码,引用 css 中的段落 class:

{{- $p := .Page -}}
{{- range (split .Inner "\n") -}}
  {{- if gt (len .) 0 }}
  <p class="p2">
    {{ . | $p.RenderString }}
  </p>
  {{- end }}
{{- end -}}

完整答案here