【问题标题】:Preserve .md formatting in a new CSS paragraph selector在新的 CSS 段落选择器中保留 .md 格式
【发布时间】:2020-06-07 21:13:04
【问题描述】:

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

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

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

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

【问题讨论】:

  • 您使用的是主题吗?您能否也发布一个输出标记的 sn-p(最终的 HTML

标签: css markdown hugo


【解决方案1】:

降价到HTML

AFAIK,您不能将输入 markdown 包装到语义部分中,例如直接使用 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>

用那些ids 生成的标题的内容。

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

Hugo 中的 Markdown

Hugo 0.60+ 使用goldmark 作为解析Markdown 的默认库,根据Configure Markup docs

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

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

【讨论】:

    【解决方案2】:

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

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

    完整答案here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-07
      • 1970-01-01
      • 2014-10-31
      • 2011-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多