Hanging Indent in .md & maintaining formatting

I’m trying to make a hanging indent to publish MLA and Chicago-formatted bibliographic references on my Hugo site. In the .css, I’ve created a new selector to perform MLA-formatted indentation of references:

  .p2 {
    padding-left: 40px;
    text-indent: -40px;
    line-height: 2.5; 
}

If I put the following code in my markdown, I get the line spacing and indentation I want, but the asterisks used to create italics become literals, as if they are escaped.

So the code below produces…

<p class="p2"> Greely, Fred, Mary Jones, and Greg Attiks. *There's a Bat in My Barn: Struggles with the New Hampshire Brown Bat*. Wildlife Press, 2012.</p>

However, if I use a line separating the paragraph class and the content, I get the markdown styling but not the spacing.

So the code below produces . . .

<p class="p2"> 

Greely, Fred, Mary Jones, and Greg Attiks. *There's a Bat in My Barn: Struggles with the New Hampshire Brown Bat*. Wildlife Press, 2012.

</p>

Solution: use a shortcode.

Template (/layouts/shortcodes/biblio-ref.html):

<p class="p2">
  {{ .Inner | .Page.RenderString }}
</p>

Markdown:

{{< biblio-ref >}}
Greely, Fred, Mary Jones, and Greg Attiks. *There's a Bat in My Barn: Struggles with the New Hampshire Brown Bat*. Wildlife Press, 2012.
{{< /biblio-ref >}}

Result:

V2. Handles multiple references, one per line.

Shortcode:

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

Markdown:

{{< biblio-ref >}}
Hugo, Victor. *The Hunchback of Notre-Dame*. Unknown publisher, 1831.
Hugo, Victor. *Les Misérables*. Unknown publisher, 1862.
Hugo, Victor. *Les Travailleurs de la Mer*. Unknown publisher, 1866.
Hugo, Victor. *Quatre-vingt-treize*. Unknown publisher, 1874.
{{< /biblio-ref >}}
1 Like

You are the master! I tip my hat sir.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.